我试图在Windows 10上使用node.js sharp进行图像处理,但require sharp-win32-x64.node
失败了。请求的.node
文件存在。require
为什么失败?
(Install Windows 10 and Git)
(open a git bash)
$ mkdir -p try_sharp
$ cd try_sharp
$ npm init -y
$ npm install sharp
$ npm list
try_sharp@1.0.0 C:Users____Desktoptry_sharp
└── sharp@0.30.1
$ ls node_modules/sharp/build/Release/
libglib-2.0-0.dll* libgobject-2.0-0.dll* libvips-42.dll* libvips-cpp.dll* sharp-win32-x64.node*
$ code index.js #// open a text editor
const s = require('sharp');
$ code node_modules/sharp/lib/sharp.js
before
module.exports = require(`../build/Release/sharp-${platformAndArch}.node`);
after
console.log('-------------')
console.log(platformAndArch)
module.exports = require(`../build/Release/sharp-${platformAndArch}.node`);
console.log('OK')
$ node index.js
-------------
win32-x64
C:Users____Desktoptry_sharpnode_modulessharplibsharp.js:33
throw new Error(help.join('n'));
Error:
Something went wrong installing the "sharp" module
The specified module could not be found.
\?C:Users____Desktoptry_sharpnode_modulessharpbuildReleasesharp-win32-x64.node
我发现了一个版本特定的问题线程。我的问题已经解决了。谢谢https://github.com/lovell/sharp/issues/3086