reactjs 盖茨比发展:安装“sharp”模块时出错

dy1byipe  于 2023-01-08  发布在  React
关注(0)|答案(5)|浏览(351)

我刚从Gatsby的一个启动模板克隆了一个git--在运行"gatsby develope"时遇到了这个错误。我删除了node模块,以及node模块中的sharp模块。没有用。请让我知道现在发生了什么!:-)

PS C:\Users\ipche\gatsby-strapi-starter> gatsby develop
success open and validate gatsby-configs - 0.073s

 ERROR 

Something went wrong installing the "sharp" module

Cannot find module '../build/Release/sharp.node'
Require stack:
- C:\Users\ipche\gatsby-strapi-starter\node_modules\gatsby-transformer-sharp\node_modules\sharp\lib\constructor.js
- C:\Users\ipche\gatsby-strapi-starter\node_modules\gatsby-transformer-sharp\node_modules\sharp\lib\index.js
- C:\Users\ipche\gatsby-strapi-starter\node_modules\gatsby-transformer-sharp\safe-sharp.js
- C:\Users\ipche\gatsby-strapi-starter\node_modules\gatsby-transformer-sharp\extend-node-type.js
- C:\Users\ipche\gatsby-strapi-starter\node_modules\gatsby-transformer-sharp\gatsby-node.js
- C:\Users\ipche\gatsby-strapi-starter\node_modules\gatsby\dist\bootstrap\resolve-module-exports.js
- C:\Users\ipche\gatsby-strapi-starter\node_modules\gatsby\dist\bootstrap\load-plugins\validate.js
- C:\Users\ipche\gatsby-strapi-starter\node_modules\gatsby\dist\bootstrap\load-plugins\load.js
- C:\Users\ipche\gatsby-strapi-starter\node_modules\gatsby\dist\bootstrap\load-plugins\index.js
- C:\Users\ipche\gatsby-strapi-starter\node_modules\gatsby\dist\bootstrap\index.js
- C:\Users\ipche\gatsby-strapi-starter\node_modules\gatsby\dist\commands\develop-process.js
- C:\Users\ipche\gatsby-strapi-starter\.cache\tmp-19076-nq3SvOAJn7yo

- Remove the "node_modules/sharp" directory, run "npm install" and look for errors
- Consult the installation documentation at https://sharp.pixelplumbing.com/en/stable/install/
- Search for this error at https://github.com/lovell/sharp/issues

在此运行"npm生成"

C:\Users\ipche\gatsby-strapi-starter\node_modules\gatsby-transformer-sharp\node_modules\sharp\src\stats.cc(130,1): error C2661: 'v8::Object::Set': no overloa 
ded function takes 2 arguments [C:\Users\ipche\gatsby-strapi-starter\node_modules\gatsby-transformer-sharp\node_modules\sharp\build\sharp.vcxproj]
C:\Users\ipche\gatsby-strapi-starter\node_modules\gatsby-transformer-sharp\node_modules\sharp\src\stats.cc(140,20): warning C4834: discarding return value of 
 function with 'nodiscard' attribute [C:\Users\ipche\gatsby-strapi-starter\node_modules\gatsby-transformer-sharp\node_modules\sharp\build\sharp.vcxproj]      
C:\Users\ipche\gatsby-strapi-starter\node_modules\gatsby-transformer-sharp\node_modules\sharp\src\pipeline.cc(1017,20): warning C4834: discarding return valu 
e of function with 'nodiscard' attribute [C:\Users\ipche\gatsby-strapi-starter\node_modules\gatsby-transformer-sharp\node_modules\sharp\build\sharp.vcxproj]  
gyp ERR! build error 
gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Users\ipche\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:314:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12)
gyp ERR! System Windows_NT 10.0.18362
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\ipche\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" 
"rebuild"
gyp ERR! cwd C:\Users\ipche\gatsby-strapi-starter\node_modules\gatsby-transformer-sharp\node_modules\sharp
gyp ERR! node -v v14.13.0
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sharp@0.22.1 install: `(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the sharp@0.22.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\ipche\AppData\Roaming\npm-cache\_logs\2020-10-06T21_03_57_721Z-debug.log

顺便说一下,我去了package.json,把sharp的依赖版本改成了"sharp@0.22.1",之前是sharp@0.26.1!
有线索吗?

    • 编辑**运行"npm安装--冗长尖锐"
ua4mk5z4

ua4mk5z41#

首先删除node_module文件夹,然后尝试下面给出的方法!
在package.json文件中手动更新sharp软件包的版本,然后尝试运行命令npm i sharp
或者先安装sharp软件包,然后运行npm install命令

vltsax25

vltsax252#

在Windows中,您可能需要额外的依赖项才能使sharp模块工作。请尝试运行:

npm install --global windows-build-tools --vs2015

安装本软件包时,它会下载并安装Microsoft免费提供的Visual C++ Build Tools 2015。这些工具是编译流行的原生模块所必需的。它还将安装Python 2.7,适当地配置您的机器和npm。
有关详细信息,请查看Gatsby on Windows docs

hm2xizp9

hm2xizp93#

在我的Windows机器上,另一个可能的解决方案是更新所有相关的gatsby插件(用于图像)。当然,我是用yarn做的,就像建议的那样,事先删除节点模块。

yarn upgrade-interactive --latest

选择你需要的onces,希望能解决错误。

sulc1iza

sulc1iza4#

问题可能是任何东西,但对我有效的是降级我的nodejs版本,特别是使用nvm降级到**14.15.0**。

  • 降级nodejs版本。
  • 从根文件夹中删除任何package-lock.jsonyarn-lock.json
  • 删除node_modules文件夹。
  • 删除.cache文件夹。
  • 运行npm installyarn install。希望它能解决这个问题,如果它不能,你可以参考库的问题页面,更具体地说,在this issue
wa7juj8i

wa7juj8i5#

试试这个

rm -rf node_modules
nvm use 14.17.1
npm install

相关问题