首页 > 解决方案 > npm 安装失败 gatsby 开发博客

问题描述

我已经在我的 gatsby 开发博客的这个问题上花费了几个小时。我从我的存储库中克隆了它并运行npm install了 sudo 权限,但它失败了。谁能告诉我是什么问题?

这是我得到的错误:

localhost@localhost:~/Desktop/devBlog$ sudo npm install
[sudo] password for hellRaiser: 
npm WARN tarball tarball data for typeface-montserrat@0.0.54 (sha512-Typhap0PWT299+Va0G/8ZtycHMXrH4gBWKfiW977KEBx5rXUUCa70gvqLx1fdA0WAo6bhSAQmo8uc+QFAmjPww==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for typeface-merriweather@0.0.72 (sha512-gO0+fcZ1fTyKUsYY1ltYOOTI6FmBGeEdyIfeQg9NL8aInndk0feiJJVJsKHm/DiyYrnQEezraAQhz/KQoqMGtw==) seems to be corrupted. Trying one more time.

> sharp@0.21.3 install /home/hellRaiser/Desktop/devBlog/node_modules/sharp
> (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)

ERR! sharp EACCES: permission denied, mkdir '/root/.npm'    
info sharp Attempting to build from source via node-gyp but this may fail due to the above error
info sharp Please see https://sharp.pixelplumbing.com/page/install for required dependencies
gyp WARN EACCES current user ("hellRaiser") does not have permission to access the dev dir "/root/.cache/node-gyp/12.16.3"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/home/hellRaiser/Desktop/devBlog/node_modules/sharp/.node-gyp"
make: Entering directory '/home/hellRaiser/Desktop/localhost@localhost:~/Desktop/devBlog$ sudo npm install
[sudo] password for hellRaiser: 
npm WARN tarball tarball data for typeface-montserrat@0.0.54 (sha512-Typhap0PWT299+Va0G/8ZtycHMXrH4gBWKfiW977KEBx5rXUUCa70gvqLx1fdA0WAo6bhSAQmo8uc+QFAmjPww==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for typeface-merriweather@0.0.72 (sha512-gO0+fcZ1fTyKUsYY1ltYOOTI6FmBGeEdyIfeQg9NL8aInndk0feiJJVJsKHm/DiyYrnQEezraAQhz/KQoqMGtw==) seems to be corrupted. Trying one more time.

> sharp@0.21.3 install /home/hellRaiser/Desktop/devBlog/node_modules/sharp
> (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)

ERR! sharp EACCES: permission denied, mkdir '/root/.npm'
info sharp Attempting to build from source via node-gyp but this may fail due to the above error
info sharp Please see https://sharp.pixelplumbing.com/page/install for required dependencies
gyp WARN EACCES current user ("hellRaiser") does not have permission to access the dev dir "/root/.cache/node-gyp/12.16.3"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/home/hellRaiser/Desktop/devBlog/node_modules/sharp/.node-gyp"
make: Entering directory '/home/hellRaiser/Desktop/devBlog/node_modules/sharp/build'
  TOUCH Release/obj.target/libvips-cpp.stamp
  CXX(target) Release/obj.target/sharp/src/common.o
../src/common.cc:25:10: fatal error: vips/vips8: No such file or directory
   25 | #include <vips/vips8>
      |          ^~~~~~~~~~~~
compilation terminated.
make: *** [sharp.target.mk:138: Release/obj.target/sharp/src/common.o] Error 1
make: Leaving directory '/home/hellRaiser/Desktop/devBlog/node_modules/sharp/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:310:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Linux 5.4.0-26-generic
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/hellRaiser/Desktop/devBlog/node_modules/sharp
gyp ERR! node -v v12.16.3
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok 
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.7 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sharp@0.21.3 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.21.3 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!     /root/.npm/_logs/2020-05-02T08_52_17_386Z-debug.log
localhost@localhost:~/Desktop/devBlog$ 

devBlog/node_modules/sharp/build'
  TOUCH Release/obj.target/libvips-cpp.stamp
  CXX(target) Release/obj.target/sharp/src/common.o
../src/common.cc:25:10: fatal error: vips/vips8: No such file or directory
   25 | #include <vips/vips8>
      |          ^~~~~~~~~~~~
compilation terminated.
make: *** [sharp.target.mk:138: Release/obj.target/sharp/src/common.o] Error 1
make: Leaving directory '/home/hellRaiser/Desktop/devBlog/node_modules/sharp/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:310:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Linux 5.4.0-26-generic
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/hellRaiser/Desktop/devBlog/node_modules/sharp
gyp ERR! node -v v12.16.3
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok 
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.7 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sharp@0.21.3 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.21.3 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!     /root/.npm/_logs/2020-05-02T08_52_17_386Z-debug.log
localhost@localhost:~/Desktop/devBlog$ 

标签: node.jsubuntunpmgatsbynode-gyp

解决方案


这可能是由于未安装构建工具。我也遇到了这个错误,我为解决这个问题而采取的步骤:

  1. sudo apt-get 更新
  2. sudo apt-get install build-essential
  3. sudo apt autoremove (仅当它这样说时)

npm install工作。

我在ubuntu上。如果您在 Mac 上,可以尝试安装 xcode 工具。

如果上述方法不起作用,那么问题很可能是由于节点版本不受支持。就我而言,切换到节点版本8.15.0有效。


推荐阅读