【问题标题】:Gatsby Develop : Something went wrong installing the "sharp" moduleGatsby Develop:安装“sharp”模块时出了点问题
【发布时间】:2021-01-21 19:19:07
【问题描述】:

我刚刚从 Gatsby 的入门模板上做了一个 git clone —— 当我运行“gatsby develop”时遇到了这个错误。我已经删除了 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 build”

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!

有什么线索吗?

编辑 Ran ' npm install --verbose sharp'

 1 Error(s)

Time Elapsed 00:00:11.67
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\sharp
gyp ERR! node -v v14.13.0
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok 
npm verb lifecycle sharp@0.22.1~install: unsafe-perm in lifecycle true
npm verb lifecycle sharp@0.22.1~install: PATH: C:\Users\ipche\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\ipche\gatsby-strapi-starter\node_modules\sharp\node_modules\.bin;C:\Users\ipche\gatsby-strapi-starter\node_modules\.bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Python38\Scripts\;C:\Python38\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\ProgramData\chocolatey\bin;C:\Program Files\PuTTY\;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\Users\ipche\anaconda3;C:\Users\ipche\anaconda3\Library\mingw-w64\bin;C:\Users\ipche\anaconda3\Library\usr\bin;C:\Users\ipche\anaconda3\Library\bin;C:\Users\ipche\anaconda3\Scripts;C:\Users\ipche\AppData\Local\Microsoft\WindowsApps;C:\Users\ipche\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\ipche\AppData\Local\GitHubDesktop\bin;C:\Panda3D-1.10.6-x64\python;C:\Panda3D-1.10.6-x64\python\Scripts;C:\Panda3D-1.10.6-x64\bin;C:\Users\ipche\Documents\GitHub\feelDetection\Panda3D-1.10.6-x64\python;C:\Users\ipche\Documents\GitHub\feelDetection\Panda3D-1.10.6-x64\python\Scripts;C:\Users\ipche\Documents\GitHub\feelDetection\Panda3D-1.10.6-x64\bin;C:\Users\ipche\AppData\Roaming\npm
npm verb lifecycle sharp@0.22.1~install: CWD: C:\Users\ipche\gatsby-strapi-starter\node_modules\sharp
npm info lifecycle sharp@0.22.1~install: Failed to exec install script
npm timing action:install Completed in 15700ms
npm verb unlock done using C:\Users\ipche\AppData\Roaming\npm-cache\_locks\staging-4a5f00369a03df36.lock for C:\Users\ipche\gatsby-strapi-starter\node_modules\.staging
npm timing stage:rollbackFailedOptional Completed in 250ms
npm timing stage:runTopLevelLifecycles Completed in 39766ms

【问题讨论】:

    标签: reactjs gatsby


    【解决方案1】:

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

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

    安装此软件包后,它会下载并安装 Microsoft 免费提供的 Visual C++ Build Tools 2015。这些工具是编译流行的本机模块所必需的。它还将安装 Python 2.7、配置您的机器和适当的 npm。

    查看Gatsby on Windows docs了解更多信息。

    【讨论】:

      【解决方案2】:

      先删除 node_module 文件夹,然后试试下面给出的方法!这对我有用

      在package.json文件中手动更新sharp包的版本,然后尝试运行命令npm i sharp

      或者先安装sharp包,然后运行命令npm install

      【讨论】:

        【解决方案3】:

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

        yarn upgrade-interactive --latest
        

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

        【讨论】:

          【解决方案4】:

          问题可能是任何问题,但对我有用的是降级我的 nodejs 版本,特别是使用nvm 降级到 14.15.0。 要遵循的步骤:

          • 降级 nodejs 版本。
          • 从根文件夹中删除任何package-lock.jsonyarn-lock.json
          • 删除node_modules文件夹。
          • 删除.cache文件夹。
          • 运行npm installyarn install。 希望它可以解决问题,如果没有,您可以参考图书馆的问题页面,更具体地说是this issue

          【讨论】:

            猜你喜欢
            • 2021-03-07
            • 2022-08-23
            • 2021-08-06
            • 2022-01-21
            • 2021-01-07
            • 2019-05-27
            • 2020-06-04
            • 2021-07-01
            • 1970-01-01
            相关资源
            最近更新 更多