javascript 错误:找不到模块“./build/Release/sharp”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33566693/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 16:38:02  来源:igfitidea点击:

Error: Cannot find module './build/Release/sharp'

javascriptnode.js

提问by Daimen Worrall

I'm trying to run some NodeJS code using Sharp and i'm getting the following error:

我正在尝试使用 Sharp 运行一些 NodeJS 代码,但出现以下错误:

    [root@localhost myapp-backend]# node server.js 

module.js:340
    throw err;
    ^
Error: Cannot find module './build/Release/sharp'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/root/myapp-backend/node_modules/sharp/index.js:11:13)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/root/myapp-backend/server.js:277:13)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:935:3

Any ideas?

有任何想法吗?

Thank you.

谢谢你。

回答by Juergen Amft

Turns out the Debian 8.x distribution I used did not include vips but I did not get an error message. Running

原来我使用的 Debian 8.x 发行版不包含 vips,但我没有收到错误消息。跑步

apt-get install libvips

followed by

其次是

npm install sharp

resolved the problem and sharp is finally installed and working.

解决了问题,夏普终于安装并工作了。

回答by JavaScript Warrior

It's probably due to Sharp not getting installed. When I installed it via npm, there were no errors, but when I went into node_modules/sharp, three were no build files.

这可能是由于 Sharp 没有安装。当我通过 npm 安装它时,没有错误,但是当我进入时node_modules/sharp,三个没有构建文件。

You can try to build it by doing
node-gyp rebuild

你可以尝试通过做来构建它
node-gyp rebuild

But, before that, make sure you have Vips installed - that's a lib that Sharp uses. On Mac you'd do
brew install homebrew/science/vips --with-webp --with-graphicsmagick

但是,在此之前,请确保您已安装 Vips - 这是 Sharp 使用的库。在 Mac 上你会这样做
brew install homebrew/science/vips --with-webp --with-graphicsmagick

After you build the Sharp library, you should be good to go.

构建 Sharp 库后,您应该可以开始使用了。

回答by Miro

What worked for me was updating to the latest Node 13 instead of the Node 8 that apt-get provides by default. Answering just for future reference.

对我有用的是更新到最新的 Node 13 而不是 apt-get 默认提供的 Node 8。回答仅供参考。