本文介绍了安装“锋利"时出了点问题模块,在 webpack 中使用 node-loader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 sharpwebpacknode-loader 一起使用,但出现此错误:

D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:150011抛出新的错误(错误);^错误:安装锋利"时出了点问题模块节点加载器:错误:找不到指定的模块.D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server/33c1e48f049ce3285905e286d212a201.node- 删除node_modules/sharp";目录然后运行npm install --ignore-scripts=false --verbose"并寻找错误- 请参阅 https://sharp.pixelplumbing.com/install 上的安装文档- 在 https://github.com/lovell/sharp/issues 搜索此错误在 Object.EmBj (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:150011:9)在 __webpack_require__ (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:27:30)在 Object.Tbcg (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:251632:15)在 __webpack_require__ (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:27:30)在 Module.dMKD (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:324313:63)在 __webpack_require__ (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:27:30)在 Module.mWHM (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:405859:77)在 __webpack_require__ (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:27:30)在 Module.WXK/(D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:271250:65)在 __webpack_require__ (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:27:30)在 D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:118:18在对象(D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:121:10)←[90m at Module._compile (internal/modules/cjs/loader.js:1156:30)←[39m←[90m 在 Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)←[39m←[90m at Module.load (internal/modules/cjs/loader.js:1000:32)←[39m←[90m at Function.Module._load (internal/modules/cjs/loader.js:899:14)←[39m←[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)←[39m←[90m at internal/main/run_main_module.js:18:47←[39m

我从node_modules"中删除了 sharp 然后重新安装它,但得到了同样的错误

>npm 缓存清理 -f>npm i --verboseSharp@latest

安装sharp的详细输出是:

D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx>npm i --verboseSharp@latestnpm info 如果它以 ok 结尾就有效npm 动词 cli [npm 动词 cli 'C:\\Program Files\\nodejs\\node.exe',npm 动词 cli 'C:\\Users\\eldeeb\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',npm 动词 cli 'i',npm 动词 cli '--verbose',npm 动词 cli 'sharp@latest'npm 动词 cli ]使用 npm@6.9.0 的 npm 信息使用 node@v12.16.2 的 npm 信息npm 动词 npm-session c41d87c77d3d7180npm http fetch GET 200 https://registry.npmjs.org/sharp 1417msnpm http fetch GET 200 https://registry.npmjs.org/sharp/-/sharp-0.27.0.tgz 644msnpm 计时阶段:loadCurrentTree 在 6364ms 内完成npm 计时阶段:loadIdealTree:cloneCurrentTree 37ms 内完成npm 计时阶段:loadIdealTree:loadShrinkwrap 1936ms 完成npm http fetch GET 200 https://registry.npmjs.org/array-flatten 218msnpm http fetch GET 200 https://registry.npmjs.org/array-flatten/-/array-flatten-3.0.0.tgz 278msnpm http fetch GET 200 https://registry.npmjs.org/prebuild-install 507msnpm http fetch GET 200 https://registry.npmjs.org/npmlog 511msnpm http fetch GET 200 https://registry.npmjs.org/simple-get 545msnpm http fetch GET 200 https://registry.npmjs.org/tar-fs 638msnpm http fetch GET 200 https://registry.npmjs.org/semver 643msnpm http fetch GET 200 https://registry.npmjs.org/node-addon-api 654msnpm http fetch GET 200 https://registry.npmjs.org/detect-libc 659msnpm http fetch GET 200 https://registry.npmjs.org/prebuild-install/-/prebuild-install-6.0.0.tgz 156msnpm http fetch GET 200 https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz 158msnpm http fetch GET 200 https://registry.npmjs.org/simple-get/-/simple-get-4.0.0.tgz 151msnpm http fetch GET 200 https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.1.tgz 468msnpm http fetch GET 200 https://registry.npmjs.org/semver/-/semver-7.3.4.tgz 471msnpm http fetch GET 200 https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz 464msnpm http fetch GET 200 https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.1.0.tgz 644msnpm http fetch GET 200 https://registry.npmjs.org/are-we-there-yet 122msnpm http fetch GET 200 https://registry.npmjs.org/gauge 306msnpm http fetch GET 200 https://registry.npmjs.org/console-control-strings 319msnpm http fetch GET 200 https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz 424msnpm http fetch GET 200 https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz 436msnpm http fetch GET 200 https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz 626msnpm http fetch GET 200 https://registry.npmjs.org/delegates 182msnpm http fetch GET 200 https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz 355msnpm http fetch GET 200 https://registry.npmjs.org/has-unicode 150msnpm http fetch GET 200 https://registry.npmjs.org/wide-align 158msnpm http fetch GET 200 https://registry.npmjs.org/strip-ansi 166msnpm http fetch GET 200 https://registry.npmjs.org/string-width 170msnpm http fetch GET 200 https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz 216msnpm http fetch GET 200 https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz 232msnpm http fetch GET 200 https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz 242msnpm http fetch GET 200 https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz 323msnpm http fetch GET 200 https://registry.npmjs.org/code-point-at 248msnpm http fetch GET 200 https://registry.npmjs.org/is-fullwidth-code-point 260msnpm http fetch GET 200 https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz 335msnpm http fetch GET 200 https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz 364msnpm http fetch GET 200 https://registry.npmjs.org/number-is-nan 221msnpm http fetch GET 200 https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz 198msnpm http fetch GET 200 https://registry.npmjs.org/ansi-regex 294msnpm http fetch GET 200 https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz 235msnpm http fetch GET 200 https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz 129msnpm http fetch GET 200 https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz 659msnpm http fetch GET 200 https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz 673msnpm http fetch GET 200 https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz 167msnpm http fetch GET 200 https://registry.npmjs.org/expand-template 196msnpm http fetch GET 200 https://registry.npmjs.org/which-pm-runs 441msnpm http fetch GET 200 https://registry.npmjs.org/noop-logger 445msnpm http fetch GET 200 https://registry.npmjs.org/node-abi 449msnpm http fetch GET 200 https://registry.npmjs.org/napi-build-utils 456msnpm http fetch GET 200 https://registry.npmjs.org/simple-get/-/simple-get-3.1.0.tgz 448msnpm http fetch GET 200 https://registry.npmjs.org/expand-template/-/expand-template-2.0.3.tgz 263msnpm http fetch GET 200 https://registry.npmjs.org/mkdirp-classic 473msnpm http fetch GET 200 https://registry.npmjs.org/github-from-package 479msnpm http fetch GET 200 https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz 549msnpm http fetch GET 200 https://registry.npmjs.org/node-abi/-/node-abi-2.19.3.tgz 557msnpm http fetch GET 200 https://registry.npmjs.org/noop-logger/-/noop-logger-0.1.1.tgz 575msnpm http fetch GET 200 https://registry.npmjs.org/which-pm-runs/-/which-pm-runs-1.0.0.tgz 580msnpm http fetch GET 200 https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz 561msnpm http fetch GET 200 https://registry.npmjs.org/napi-build-utils/-/napi-build-utils-1.0.2.tgz 571msnpm http fetch GET 200 https://registry.npmjs.org/semver/-/semver-5.7.1.tgz 336msnpm http fetch GET 200 https://registry.npmjs.org/simple-concat 280msnpm http fetch GET 200 https://registry.npmjs.org/decompress-response 299msnpm http fetch GET 200 https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz 131msnpm http fetch GET 200 https://registry.npmjs.org/decompress-response/-/decompress-response-4.2.1.tgz 147msnpm http fetch GET 200 https://registry.npmjs.org/mimic-response 213msnpm http fetch GET 200 https://registry.npmjs.org/mimic-response/-/mimic-response-2.1.0.tgz 183msnpm http fetch GET 200 https://registry.npmjs.org/tar-stream 206msnpm http fetch GET 200 https://registry.npmjs.org/tar-stream/-/tar-stream-2.2.0.tgz 293msnpm http fetch GET 200 https://registry.npmjs.org/fs-constants 162msnpm http fetch GET 200 https://registry.npmjs.org/bl 202msnpm http fetch GET 200 https://registry.npmjs.org/readable-stream 228msnpm http fetch GET 200 https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz 188msnpm http fetch GET 200 https://registry.npmjs.org/bl/-/bl-4.0.3.tgz 157msnpm http fetch GET 200 https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz 154msnpm http fetch GET 200 https://registry.npmjs.org/buffer 858msnpm http fetch GET 200 https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz 159msnpm http fetch GET 200 https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz 245msnpm http fetch GET 200 https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz 105msnpm 计时阶段:loadIdealTree:loadAllDepsIntoIdealTree 在 17386ms 内完成npm 计时阶段:loadIdealTree 20212ms 完成npm 计时阶段:generateActionsToTake 在 251ms 内完成npm动词correctMkdir C:\Users\eldeeb\AppData\Roaming\npm-cache\_locks CorrectMkdir not in flight;初始化npm 动词 makeDirectory C:\Users\eldeeb\AppData\Roaming\npm-cache\_locks 创建不在飞行中;初始化npm 动词 makeCacheDir UID &GID 与 win32 无关npm 动词锁定使用 C:\Users\eldeeb\AppData\Roaming\npm-cache\_locks\staging-ff976866a950c511.lock for D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\node_modules\.stagingnpm http fetch GET 200 https://registry.npmjs.org/fsevents/-/fsevents-1.2.13.tgz 250msnpm http fetch GET 200 https://registry.npmjs.org/fsevents/-/fsevents-2.1.3.tgz 260msnpm http fetch GET 200 https://registry.npmjs.org/fsevents/-/fsevents-1.2.13.tgz 255msnpm 计时动作:提取 304 毫秒完成npm info 生命周期未定义~预卸载:未定义npm info 生命周期未定义~卸载:未定义npm 计时动作:unbuild 在 10ms 内完成npm 计时动作:remove 0ms 内完成npm 计时动作:finalize 60ms 内完成npm 计时动作:refresh-package-json 105ms 完成npm info 生命周期 array-flatten@3.0.0~preinstall: array-flatten@3.0.0npm 信息生命周期 semver@7.3.4~预安装:semver@7.3.4npm info 生命周期sharp@0.27.0~预安装:sharp@0.27.0npm 计时动作:preinstall 17ms 完成npm info linkStuff array-flatten@3.0.0npm 信息链接材料 semver@7.3.4npm 动词 linkBins [npm 动词 linkBins { semver: 'bin/semver.js' },npm动词linkBins 'D:\\Downloads\\__projects\\dev\\NodeJs\\@eng-dibo\\ngx\\node_modules\\sharp\\node_modules\\.bin',npm 动词 linkBins falsenpm 动词 linkBins ]npm info linkStuffSharp@0.27.0npm 计时动作:build 70ms 完成npm info 生命周期 array-flatten@3.0.0~install: array-flatten@3.0.0npm 信息生命周期 semver@7.3.4~安装:semver@7.3.4npm info 生命周期sharp@0.27.0~安装:sharp@0.27.0>sharp@0.27.0 安装 D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\node_modules\sharp>(节点安装/libvips && 节点安装/dll-copy && prebuild-install) ||(node-gyp 重建 && 节点安装/dll-copy)信息锐利下载 https://github.com/lovell/sharp-libvips/releases/download/v8.10.5/libvips-8.10.5-win32-x64.tar.brinfosharp Creating D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\node_modules\sharp\build\Release将 DLL 从 D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\node_modules\sharp\vendor\8.10.5\lib 复制到 D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\点头e_modules\sharp\build\Release预构建安装信息开始预构建安装版本 6.0.0预构建安装信息查找缓存预构建 @ C:\Users\eldeeb\AppData\Roaming\npm-cache\_prebuilds\9cc5aa-sharp-v0.27.0-napi-v3-win32-x64.tar.gz预构建安装信息找到缓存的预构建预构建安装信息解包@ C:\Users\eldeeb\AppData\Roaming\npm-cache\_prebuilds\9cc5aa-sharp-v0.27.0-napi-v3-win32-x64.tar.gz预构建安装信息解压到 D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\node_modules\sharp\build\Release\sharp.nodeprebuild-install info install 成功安装预构建的二进制文件!npm 动词生命周期sharp@0.27.0~install: unsafe-perm inlifecycle truenpm 动词生命周期sharp@0.27.0~install: PATH: C:\Users\eldeeb\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;D:\Downloads\__projects\dev\不deJs\@eng-dibo\ngx\node_modules\sharp\node_modules\.bin;D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\node_modules\.bin;C:\Program Files (x86)\英特尔\iCLS 客户端\;C:\Prgram Files\Intel\iCLS Client\;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\WinMerge;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\ProgramFiles (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\程序文件 (x86)\Yarn\bin\;C:\Program Files\heroku\bin;C:\Users\eldeeb\AppData\Roaming\npm;C:\Users\eldeeb\AppData\Local\atom\bin;C:\Users\eldeeb\AppData\Local\Yarn\binnpm 动词生命周期sharp@0.27.0~install: CWD: D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\node_modules\sharpnpm 定时审计提交 6102ms 完成npm http fetch POST 200 https://registry.npmjs.org/-/npm/v1/security/audits/quick 6102msnpm 定时审计主体 1ms 内完成npm 计时动作:安装 30506ms 完成npm info 生命周期 array-flatten@3.0.0~postinstall: array-flatten@3.0.0npm 信息生命周期 semver@7.3.4~postinstall: semver@7.3.4npm info 生命周期sharp@0.27.0~postinstall:sharp@0.27.0npm 计时动作:postinstall 9ms 内完成npm 动词解锁使用 C:\Users\eldeeb\AppData\Roaming\npm-cache\_locks\staging-ff976866a950c511.lock 完成,用于 D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\node_modules\.分期npm 计时阶段:executeActions 在 31157ms 内完成npm 计时阶段:rollbackFailedOptional 19ms 内完成npm 计时阶段:runTopLevelLifecycles 在 58678ms 内完成npm 动词保存 [ { name: 'sharp', spec: '^0.27.0', save: 'dependencies' } ]npm 动词 shrinkwrap 跳过 package.json 的写入,因为没有变化.npm info 生命周期未定义~preshrinkwrap: 未定义npm info 生命周期未定义~shrinkwrap: 未定义npm 动词shrinkwrap 跳过对 package-lock.json 的写入,因为没有更改.npm info 生命周期未定义~postshrinkwrap: 未定义npm WARN @angular-devkit/build-angular@0.1001.7 需要@angular/localize@^10.0.0 的同级,但没有安装.您必须自己安装对等依赖项.npm WARN @angular-devkit/build-angular@0.1001.7 需要 ng-packagr@^10.0.0 的同级,但没有安装.您必须自己安装对等依赖项.npm WARN @fortawesome/angular-fontawesome@0.6.1 需要 @angular/core@^9.0.0 的对等点,但没有安装.您必须自己安装对等依赖项.npm WARN @fortawesome/angular-fontawesome@0.6.1 需要 tslib@^1.10.0 的同级,但没有安装.您必须自己安装对等依赖项.npm WARN jsdom@16.4.0 需要 canvas@^2.5.0 的同级,但没有安装.您必须自己安装对等依赖项.npm WARN ngx-loading@8.0.0 需要 @angular/common@^8.0.0 的对等点,但没有安装.您必须自己安装对等依赖项.npm WARN ngx-loading@8.0.0 需要 @angular/core@^8.0.0 的对等点,但没有安装.您必须自己安装对等依赖项.npm WARN sass-loader@10.0.1 需要 node-sass@^4.0.0 的同级,但没有安装.您必须自己安装对等依赖项.npm WARN sass-loader@10.0.1 需要一个 Fibers@>= 3.1.0 但没有安装.您必须自己安装对等依赖项.npm WARN webpack-subresource-integrity@1.4.1 需要 html-webpack-plugin@^2.21.0 ||~3 ||>=4.0.0-alpha.2 <5 但没有安装.您必须安装对等依赖自己决定.npm WARN ws@7.4.0 需要 bufferutil@^4.0.1 的同级,但没有安装.您必须自己安装对等依赖项.npm WARN ws@7.4.0 需要 utf-8-validate@^5.0.2 的对等体,但没有安装.您必须自己安装对等依赖项.npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\webpack-dev-server\node_modules\fsevents):npm WARN notsup SKIPPING OPTIONAL DEPENDENCY:fsevents@1.2.13不受支持的平台:想要{os":darwin",arch":any"}(当前:{os":win32";,"arch":"x64"})npm 动词 notsup 跳过可选依赖项:有效操作系统:达尔文npm 动词 notsup SKIPPING OPTIONAL DEPENDENCY: Valid Arch: anynpm 动词 notsup 跳过可选依赖项:实际操作系统:win32npm 动词 notsup 跳过可选依赖项:实际 Arch:x64npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules\fsevents):npm WARN notsup SKIPPING OPTIONAL DEPENDENCY:fsevents@2.1.3不受支持的平台:想要{os":darwin",arch":any"}(当前:{os":win32";,"arch":"x64"})npm 动词 notsup 跳过可选依赖项:有效操作系统:达尔文npm 动词 notsup SKIPPING OPTIONAL DEPENDENCY: Valid Arch: anynpm 动词 notsup 跳过可选依赖项:实际操作系统:win32npm 动词 notsup 跳过可选依赖项:实际 Arch:x64npm WARN 可选 SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\watchpack-chokidar2\node_modules\fsevents):npm WARN notsup SKIPPING OPTIONAL DEPENDENCY:fsevents@1.2.13不受支持的平台:想要{os":darwin",arch":any"}(当前:{os":win32";,"arch":"x64"})npm 动词 notsup 跳过可选依赖项:有效操作系统:达尔文npm 动词 notsup SKIPPING OPTIONAL DEPENDENCY: Valid Arch: anynpm 动词 notsup 跳过可选依赖项:实际操作系统:win32npm 动词 notsup 跳过可选依赖项:实际 Arch:x64+ 锐利@0.27.0添加了来自 69 个贡献者的 3 个包并在 60.317 秒内审计了 1986 个包发现 11 个漏洞(7 个低、1 个中等、3 个高)运行 `npm audit fix` 来修复它们,或者运行 `npm audit` 了解详情npm 动词 exit [ 0, true ]npm 计时 npm 60904ms 完成npm 信息正常

我在 webpack 中添加了 node-loader:

config.module.rules.push({ 测试:/\.ts$/,加载器:ts-loader";},{测试:/\.node$/,使用:节点加载器"});

操作系统:Windows 8.1

这个问题是 angular 特有的,我刚刚创建了一个全新的 angular 项目并启用了通用应用程序.

最小复制:

https://github.com/eng-dibo/ng-sharp-issue

运行此复制的步骤:

1- 克隆这个 repo https://github.com/eng-dibo/ng-sharp-issue

2- inatsll 包 npm i

3- 构建服务器 npm run build:server:dev

->{optional} 构建整个项目(浏览器和服务器)并为其提供服务 npm run start

->为了说明,脚本 build:ssr 已重命名为 build:serverbuild:server:dev.

这会生成 dist 目录包含 main.jssharp-*.node 文件

4- 运行服务器node dist/main

错误:安装锋利"时出了点问题模块节点加载器:错误:找不到指定的模块.//sharp-ac5709806d227d1d966f7f0b76814d78.node

如果我们从 webpack 配置中删除了 node-loader,我们将得到 error: Unexpected character ' ' (1:2),如详细的步骤"中所述创建此 repo"下面一步一步来.

制作此复制品的步骤:(供参考)

1- 创建新的 Angular 项目:

ng 新的 ngxng serve -o//

2- 启用通用应用

ng 添加@nguniversal/express-enginenpm run build:ssr &npm run serve 

3- 给 server.ts

添加尖锐

//server.tsimport * as sharp from sharp";尖锐('./image.jpg')npm run build:ssr <-- 失败,错误:意外字符 ' ' (1:2)

4- 使用node-loader加载.node文件(在sharp包内),我们需要使用自定义webpack在Angular中修改webpack配置

npm i -D @angular-builders/custom-webpack node-loader ts-loader
//angular.json{...服务器:{builder":@angular-builders/custom-webpack:server",选项":{customWebpackConfig":{路径":./webpack.server.config.js"}}}}
//webpack.server.config.js(简化)module.exports = (config, options) =>{//从 Angular 中移除 webpack 配置,除了 'resolve',并添加规则(ts-loader, node-loader)配置 = {模式:发展",解决:config.resolve,入口: {主要:[./server.ts"]},目标:节点",统计信息:{颜色:假},模块: {规则: [{ 测试:/\.ts$/,加载器:ts-loader";},{测试:/\.node$/,加载器:节点加载器",选项:{名称:[名称]-[contenthash].[ext]";}}]}};返回配置;}
npm run build:ssr 
解决方案

删除node_modules/sharp"目录然后运行npm install --ignore-scripts=false --verboseSharp"这应该可以完美运行

I use sharp and webpack with node-loader but I got this error:

D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:150011
  throw new Error(error);
  ^

Error:
Something went wrong installing the "sharp" module

node-loader:
Error: The specified module could not be found.
D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server/33c1e48f049ce3285905e286d212a201.node

- Remove the "node_modules/sharp" directory then run
  "npm install --ignore-scripts=false --verbose" and look for errors
- Consult the installation documentation at https://sharp.pixelplumbing.com/install
- Search for this error at https://github.com/lovell/sharp/issues

    at Object.EmBj (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:150011:9)
    at __webpack_require__ (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:27:30)
    at Object.Tbcg (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:251632:15)
    at __webpack_require__ (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:27:30)
    at Module.dMKD (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:324313:63)
    at __webpack_require__ (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:27:30)
    at Module.mWHM (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:405859:77)
    at __webpack_require__ (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:27:30)
    at Module.WXK/ (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:271250:65)
    at __webpack_require__ (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:27:30)
    at D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:118:18
    at Object.<anonymous> (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:121:10)
←[90m    at Module._compile (internal/modules/cjs/loader.js:1156:30)←[39m
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:1000:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:899:14)←[39m
←[90m    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)←[39m
←[90m    at internal/main/run_main_module.js:18:47←[39m

I removed sharp from 'node_modules` then reinstalled it, but got the same error

> npm cache clean -f
> npm i --verbose sharp@latest

the verbose output of installing sharp is:


D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx>npm i --verbose sharp@latest
npm info it worked if it ends with ok
npm verb cli [
npm verb cli   'C:\\Program Files\\nodejs\\node.exe',
npm verb cli   'C:\\Users\\eldeeb\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
npm verb cli   'i',
npm verb cli   '--verbose',
npm verb cli   'sharp@latest'
npm verb cli ]
npm info using npm@6.9.0
npm info using node@v12.16.2
npm verb npm-session c41d87c77d3d7180
npm http fetch GET 200 https://registry.npmjs.org/sharp 1417ms
npm http fetch GET 200 https://registry.npmjs.org/sharp/-/sharp-0.27.0.tgz 644ms
npm timing stage:loadCurrentTree Completed in 6364ms
npm timing stage:loadIdealTree:cloneCurrentTree Completed in 37ms
npm timing stage:loadIdealTree:loadShrinkwrap Completed in 1936ms
npm http fetch GET 200 https://registry.npmjs.org/array-flatten 218ms
npm http fetch GET 200 https://registry.npmjs.org/array-flatten/-/array-flatten-3.0.0.tgz 278ms
npm http fetch GET 200 https://registry.npmjs.org/prebuild-install 507ms
npm http fetch GET 200 https://registry.npmjs.org/npmlog 511ms
npm http fetch GET 200 https://registry.npmjs.org/simple-get 545ms
npm http fetch GET 200 https://registry.npmjs.org/tar-fs 638ms
npm http fetch GET 200 https://registry.npmjs.org/semver 643ms
npm http fetch GET 200 https://registry.npmjs.org/node-addon-api 654ms
npm http fetch GET 200 https://registry.npmjs.org/detect-libc 659ms
npm http fetch GET 200 https://registry.npmjs.org/prebuild-install/-/prebuild-install-6.0.0.tgz 156ms
npm http fetch GET 200 https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz 158ms
npm http fetch GET 200 https://registry.npmjs.org/simple-get/-/simple-get-4.0.0.tgz 151ms
npm http fetch GET 200 https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.1.tgz 468ms
npm http fetch GET 200 https://registry.npmjs.org/semver/-/semver-7.3.4.tgz 471ms
npm http fetch GET 200 https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz 464ms
npm http fetch GET 200 https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.1.0.tgz 644ms
npm http fetch GET 200 https://registry.npmjs.org/are-we-there-yet 122ms
npm http fetch GET 200 https://registry.npmjs.org/gauge 306ms
npm http fetch GET 200 https://registry.npmjs.org/console-control-strings 319ms
npm http fetch GET 200 https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz 424ms
npm http fetch GET 200 https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz 436ms
npm http fetch GET 200 https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz 626ms
npm http fetch GET 200 https://registry.npmjs.org/delegates 182ms
npm http fetch GET 200 https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz 355ms
npm http fetch GET 200 https://registry.npmjs.org/has-unicode 150ms
npm http fetch GET 200 https://registry.npmjs.org/wide-align 158ms
npm http fetch GET 200 https://registry.npmjs.org/strip-ansi 166ms
npm http fetch GET 200 https://registry.npmjs.org/string-width 170ms
npm http fetch GET 200 https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz 216ms
npm http fetch GET 200 https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz 232ms
npm http fetch GET 200 https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz 242ms
npm http fetch GET 200 https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz 323ms
npm http fetch GET 200 https://registry.npmjs.org/code-point-at 248ms
npm http fetch GET 200 https://registry.npmjs.org/is-fullwidth-code-point 260ms
npm http fetch GET 200 https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz 335ms
npm http fetch GET 200 https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz 364ms
npm http fetch GET 200 https://registry.npmjs.org/number-is-nan 221ms
npm http fetch GET 200 https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz 198ms
npm http fetch GET 200 https://registry.npmjs.org/ansi-regex 294ms
npm http fetch GET 200 https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz 235ms
npm http fetch GET 200 https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz 129ms
npm http fetch GET 200 https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz 659ms
npm http fetch GET 200 https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz 673ms
npm http fetch GET 200 https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz 167ms
npm http fetch GET 200 https://registry.npmjs.org/expand-template 196ms
npm http fetch GET 200 https://registry.npmjs.org/which-pm-runs 441ms
npm http fetch GET 200 https://registry.npmjs.org/noop-logger 445ms
npm http fetch GET 200 https://registry.npmjs.org/node-abi 449ms
npm http fetch GET 200 https://registry.npmjs.org/napi-build-utils 456ms
npm http fetch GET 200 https://registry.npmjs.org/simple-get/-/simple-get-3.1.0.tgz 448ms
npm http fetch GET 200 https://registry.npmjs.org/expand-template/-/expand-template-2.0.3.tgz 263ms
npm http fetch GET 200 https://registry.npmjs.org/mkdirp-classic 473ms
npm http fetch GET 200 https://registry.npmjs.org/github-from-package 479ms
npm http fetch GET 200 https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz 549ms
npm http fetch GET 200 https://registry.npmjs.org/node-abi/-/node-abi-2.19.3.tgz 557ms
npm http fetch GET 200 https://registry.npmjs.org/noop-logger/-/noop-logger-0.1.1.tgz 575ms
npm http fetch GET 200 https://registry.npmjs.org/which-pm-runs/-/which-pm-runs-1.0.0.tgz 580ms
npm http fetch GET 200 https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz 561ms
npm http fetch GET 200 https://registry.npmjs.org/napi-build-utils/-/napi-build-utils-1.0.2.tgz 571ms
npm http fetch GET 200 https://registry.npmjs.org/semver/-/semver-5.7.1.tgz 336ms
npm http fetch GET 200 https://registry.npmjs.org/simple-concat 280ms
npm http fetch GET 200 https://registry.npmjs.org/decompress-response 299ms
npm http fetch GET 200 https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz 131ms
npm http fetch GET 200 https://registry.npmjs.org/decompress-response/-/decompress-response-4.2.1.tgz 147ms
npm http fetch GET 200 https://registry.npmjs.org/mimic-response 213ms
npm http fetch GET 200 https://registry.npmjs.org/mimic-response/-/mimic-response-2.1.0.tgz 183ms
npm http fetch GET 200 https://registry.npmjs.org/tar-stream 206ms
npm http fetch GET 200 https://registry.npmjs.org/tar-stream/-/tar-stream-2.2.0.tgz 293ms
npm http fetch GET 200 https://registry.npmjs.org/fs-constants 162ms
npm http fetch GET 200 https://registry.npmjs.org/bl 202ms
npm http fetch GET 200 https://registry.npmjs.org/readable-stream 228ms
npm http fetch GET 200 https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz 188ms
npm http fetch GET 200 https://registry.npmjs.org/bl/-/bl-4.0.3.tgz 157ms
npm http fetch GET 200 https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz 154ms
npm http fetch GET 200 https://registry.npmjs.org/buffer 858ms
npm http fetch GET 200 https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz 159ms
npm http fetch GET 200 https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz 245ms
npm http fetch GET 200 https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz 105ms
npm timing stage:loadIdealTree:loadAllDepsIntoIdealTree Completed in 17386ms
npm timing stage:loadIdealTree Completed in 20212ms
npm timing stage:generateActionsToTake Completed in 251ms
npm verb correctMkdir C:\Users\eldeeb\AppData\Roaming\npm-cache\_locks correctMkdir not in flight; initializing
npm verb makeDirectory C:\Users\eldeeb\AppData\Roaming\npm-cache\_locks creation not in flight; initializing
npm verb makeCacheDir UID & GID are irrelevant on win32
npm verb lock using C:\Users\eldeeb\AppData\Roaming\npm-cache\_locks\staging-ff976866a950c511.lock for D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\node_modules\.stag
ing
npm http fetch GET 200 https://registry.npmjs.org/fsevents/-/fsevents-1.2.13.tgz 250ms
npm http fetch GET 200 https://registry.npmjs.org/fsevents/-/fsevents-2.1.3.tgz 260ms
npm http fetch GET 200 https://registry.npmjs.org/fsevents/-/fsevents-1.2.13.tgz 255ms
npm timing action:extract Completed in 304ms
npm info lifecycle undefined~preuninstall: undefined
npm info lifecycle undefined~uninstall: undefined
npm timing action:unbuild Completed in 10ms
npm timing action:remove Completed in 0ms
npm timing action:finalize Completed in 60ms
npm timing action:refresh-package-json Completed in 105ms
npm info lifecycle array-flatten@3.0.0~preinstall: array-flatten@3.0.0
npm info lifecycle semver@7.3.4~preinstall: semver@7.3.4
npm info lifecycle sharp@0.27.0~preinstall: sharp@0.27.0
npm timing action:preinstall Completed in 17ms
npm info linkStuff array-flatten@3.0.0
npm info linkStuff semver@7.3.4
npm verb linkBins [
npm verb linkBins   { semver: 'bin/semver.js' },
npm verb linkBins   'D:\\Downloads\\__projects\\dev\\NodeJs\\@eng-dibo\\ngx\\node_modules\\sharp\\node_modules\\.bin',
npm verb linkBins   false
npm verb linkBins ]
npm info linkStuff sharp@0.27.0
npm timing action:build Completed in 70ms
npm info lifecycle array-flatten@3.0.0~install: array-flatten@3.0.0
npm info lifecycle semver@7.3.4~install: semver@7.3.4
npm info lifecycle sharp@0.27.0~install: sharp@0.27.0

> sharp@0.27.0 install D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\node_modules\sharp
> (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)

info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.10.5/libvips-8.10.5-win32-x64.tar.br
info sharp Creating D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\node_modules\sharp\build\Release
info sharp Copying DLLs from D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\node_modules\sharp\vendor\8.10.5\lib to D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\nod
e_modules\sharp\build\Release
prebuild-install info begin Prebuild-install version 6.0.0
prebuild-install info looking for cached prebuild @ C:\Users\eldeeb\AppData\Roaming\npm-cache\_prebuilds\9cc5aa-sharp-v0.27.0-napi-v3-win32-x64.tar.gz
prebuild-install info found cached prebuild
prebuild-install info unpacking @ C:\Users\eldeeb\AppData\Roaming\npm-cache\_prebuilds\9cc5aa-sharp-v0.27.0-napi-v3-win32-x64.tar.gz
prebuild-install info unpack resolved to D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\node_modules\sharp\build\Release\sharp.node
prebuild-install info install Successfully installed prebuilt binary!
npm verb lifecycle sharp@0.27.0~install: unsafe-perm in lifecycle true
npm verb lifecycle sharp@0.27.0~install: PATH: C:\Users\eldeeb\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;D:\Downloads\__projects\dev\No
deJs\@eng-dibo\ngx\node_modules\sharp\node_modules\.bin;D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\node_modules\.bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Pr
ogram Files\Intel\iCLS Client\;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\
Program Files (x86)\WinMerge;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program
Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Skype\Phone\;C:\
Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\Program Files (x86)\Yar
n\bin\;C:\Program Files\heroku\bin;C:\Users\eldeeb\AppData\Roaming\npm;C:\Users\eldeeb\AppData\Local\atom\bin;C:\Users\eldeeb\AppData\Local\Yarn\bin
npm verb lifecycle sharp@0.27.0~install: CWD: D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\node_modules\sharp
npm timing audit submit Completed in 6102ms
npm http fetch POST 200 https://registry.npmjs.org/-/npm/v1/security/audits/quick 6102ms
npm timing audit body Completed in 1ms
npm timing action:install Completed in 30506ms
npm info lifecycle array-flatten@3.0.0~postinstall: array-flatten@3.0.0
npm info lifecycle semver@7.3.4~postinstall: semver@7.3.4
npm info lifecycle sharp@0.27.0~postinstall: sharp@0.27.0
npm timing action:postinstall Completed in 9ms
npm verb unlock done using C:\Users\eldeeb\AppData\Roaming\npm-cache\_locks\staging-ff976866a950c511.lock for D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\node_module
s\.staging
npm timing stage:executeActions Completed in 31157ms
npm timing stage:rollbackFailedOptional Completed in 19ms
npm timing stage:runTopLevelLifecycles Completed in 58678ms
npm verb saving [ { name: 'sharp', spec: '^0.27.0', save: 'dependencies' } ]
npm verb shrinkwrap skipping write for package.json because there were no changes.
npm info lifecycle undefined~preshrinkwrap: undefined
npm info lifecycle undefined~shrinkwrap: undefined
npm verb shrinkwrap skipping write for package-lock.json because there were no changes.
npm info lifecycle undefined~postshrinkwrap: undefined
npm WARN @angular-devkit/build-angular@0.1001.7 requires a peer of @angular/localize@^10.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @angular-devkit/build-angular@0.1001.7 requires a peer of ng-packagr@^10.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @fortawesome/angular-fontawesome@0.6.1 requires a peer of @angular/core@^9.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @fortawesome/angular-fontawesome@0.6.1 requires a peer of tslib@^1.10.0 but none is installed. You must install peer dependencies yourself.
npm WARN jsdom@16.4.0 requires a peer of canvas@^2.5.0 but none is installed. You must install peer dependencies yourself.
npm WARN ngx-loading@8.0.0 requires a peer of @angular/common@^8.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN ngx-loading@8.0.0 requires a peer of @angular/core@^8.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN sass-loader@10.0.1 requires a peer of node-sass@^4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN sass-loader@10.0.1 requires a peer of fibers@>= 3.1.0 but none is installed. You must install peer dependencies yourself.
npm WARN webpack-subresource-integrity@1.4.1 requires a peer of html-webpack-plugin@^2.21.0 || ~3 || >=4.0.0-alpha.2 <5 but none is installed. You must install peer depen
dencies yourself.
npm WARN ws@7.4.0 requires a peer of bufferutil@^4.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN ws@7.4.0 requires a peer of utf-8-validate@^5.0.2 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\webpack-dev-server\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Valid OS:    darwin
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Valid Arch:  any
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Actual OS:   win32
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Actual Arch: x64
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Valid OS:    darwin
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Valid Arch:  any
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Actual OS:   win32
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Actual Arch: x64
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\watchpack-chokidar2\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Valid OS:    darwin
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Valid Arch:  any
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Actual OS:   win32
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Actual Arch: x64

+ sharp@0.27.0
added 3 packages from 69 contributors and audited 1986 packages in 60.317s
found 11 vulnerabilities (7 low, 1 moderate, 3 high)
  run `npm audit fix` to fix them, or `npm audit` for details
npm verb exit [ 0, true ]
npm timing npm Completed in 60904ms
npm info ok

I added node-loader to webpack:

config.module.rules.push(
    { test: /\.ts$/, loader: "ts-loader" },
    {
      test: /\.node$/,
      use: "node-loader"
    }
  );

OS: windows 8.1

this issue is specially occures with angular, I just created a brand new angular project and enabled universal app.

minimal reproduction:

https://github.com/eng-dibo/ng-sharp-issue

steps to run this reproduction:

1- clone this repo https://github.com/eng-dibo/ng-sharp-issue

2- inatsll packages npm i

3- build the server npm run build:server:dev

-> {optional} to build the whole project (browser & server) and serve it npm run start

-> the script build:ssr has been renamed to build:server or build:server:dev for clarification.

this generates dist dir contains main.js and sharp-*.node files

4- run the server node dist/main

Error:
Something went wrong installing the "sharp" module

node-loader:
Error: The specified module could not be found.
//sharp-ac5709806d227d1d966f7f0b76814d78.node

if we removed node-loader from webpack config, we will get error: Unexpected character '�' (1:2) as mentioned in the detailed "steps of creating this repo" step-by-step below.

steps of creating this reproduction: (for reference)

1- create new angular project:

ng new ngx
ng serve -o //<-- success

2- enable universal app

ng add @nguniversal/express-engine
npm run build:ssr & npm run serve <--success

3- add sharp to server.ts

//server.ts
import * as sharp from "sharp"
sharp('./image.jpg')

npm run build:ssr <-- faild, error: Unexpected character '�' (1:2)

4- use node-loader to load .node file (inside sharp package), we need to use custom webpack to modify webpack configuration in Angular

npm i -D @angular-builders/custom-webpack node-loader ts-loader
//angular.json
{
...
server:{
  "builder": "@angular-builders/custom-webpack:server",
   "options": {
            "customWebpackConfig": {
              "path": "./webpack.server.config.js"
            }
  }
}

}
//webpack.server.config.js (simplified)
module.exports = (config, options) => {
   //remove webpack config from Angular, except 'resolve', and add rules (ts-loader, node-loader)

config = {
    mode: "development",
    resolve: config.resolve,
    entry: {
      main: ["./server.ts"]
    },
    target: "node",
    stats: { colors: false },
    module: {
      rules: [
        { test: /\.ts$/, loader: "ts-loader" },
        {
          test: /\.node$/,
          loader: "node-loader",
          options: { name: "[name]-[contenthash].[ext]" }
        }
      ]
    }
  };

return config;

}

npm run build:ssr <-- faild
解决方案

Remove the "node_modules/sharp" directory then run"npm install --ignore-scripts=false --verbose sharp" and that should work perfectly

这篇关于安装“锋利"时出了点问题模块,在 webpack 中使用 node-loader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-19 02:49
查看更多