简体   繁体   English

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

[英]Error: Cannot find module './build/Release/sharp'

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.谢谢你。

Turns out the Debian 8.x distribution I used did not include vips but I did not get an error message.事实证明,我使用的 Debian 8.x 发行版不包含 vips,但我没有收到错误消息。 Running跑步

apt-get install libvips

followed by其次是

npm install sharp

resolved the problem and sharp is finally installed and working.解决了问题,夏普终于安装并工作了。

It's probably due to Sharp not getting installed.这可能是由于 Sharp 没有安装。 When I installed it via npm, there were no errors, but when I went into node_modules/sharp , three were no build files.当我通过 npm 安装它时,没有错误,但是当我进入node_modules/sharp ,三个没有构建文件。

You can try to build it by doing你可以尝试通过做来构建它
node-gyp rebuild

But, before that, make sure you have Vips installed - that's a lib that Sharp uses.但是,在此之前,请确保您已安装 Vips - 这是 Sharp 使用的库。 On Mac you'd do在 Mac 上你会这样做
brew install homebrew/science/vips --with-webp --with-graphicsmagick

After you build the Sharp library, you should be good to go.构建 Sharp 库后,您应该可以开始使用了。

Check if you don't have build folder on node_modules/sharp , then run:检查node_modules/sharp上是否没有 build 文件夹,然后运行:

npm i sharp

it will reinstall and builds sharp.它将重新安装并构建锋利。 (worked for me) (为我工作)

What worked for me was updating to the latest Node 13 instead of the Node 8 that apt-get provides by default.对我有用的是更新到最新的 Node 13 而不是 apt-get 默认提供的 Node 8。 Answering just for future reference.回答仅供参考。

I was getting the same error in Lambda function for s3 image crop.我在用于 s3 图像裁剪的 Lambda 函数中遇到了相同的错误。

I installed the sharp module as below and I was able to crop images.我安装了如下的sharp模块,我能够裁剪图像。

npm install --platform=linux --arch=x64 sharp

Please check "node_modules/sharp/build/build" folder for "sharp-linux-x64.node"请检查“node_modules/sharp/build/build”文件夹中的“sharp-linux-x64.node”

In my case installing the sharp for specific target version of node.js works, I used below command, but before that remove your existing node_modules folder or remove rm -rf node_modules/sharp在我的情况下,为 node.js 的特定目标版本安装Sharp,我使用了以下命令,但在此之前删除现有的node_modules文件夹或删除rm -rf node_modules/sharp

npm install --arch=x64 --platform=linux --target=16x sharp

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Rocket.Chat构建失败,错误为“找不到模块&#39;../build/Release/sharp.node&#39;” - Rocket.Chat build failing with error “Cannot find module '../build/Release/sharp.node' ” 错误:在Mac上找不到模块&#39;../build/Release/bson&#39; - Error: Cannot find module '../build/Release/bson' on Mac MongoDB - 错误:无法找到模块&#39;../build/Release/bson&#39; - MongoDB - Error: Cannot find module '../build/Release/bson' Vogels错误:错误:找不到模块&#39;./build/Release/DTraceProviderBindings&#39; - Vogels err: Error: Cannot find module './build/Release/DTraceProviderBindings' 找不到模块'../build/Release/opencv4nodejs - Cannot find module '../build/Release/opencv4nodejs 使用Browserify构建npm-错误:找不到模块 - npm build with Browserify - Error: Cannot find module 模块构建失败:错误:找不到模块'@ babel / core' - Module build failed: Error: Cannot find module '@babel/core' Microsoft NodeJS从零到英雄:找不到模块&#39;../build/Release/bson&#39;和TypeError:无法读取未定义的属性&#39;indexOf&#39; - Microsoft NodeJS Zero to Hero: Cannot find module '../build/Release/bson' and TypeError: Cannot read property 'indexOf' of undefined «Canvas» 与 NodeJS 的使用:«无法找到模块 &#39;../build/Release/canvas.node&#39;» - Utilisation of «Canvas» with NodeJS : «Cannot find module '../build/Release/canvas.node'» Lerna 错误:在 CI 构建期间找不到模块 - Lerna error: cannot find module during CI build
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM