簡體   English   中英

我無法使用 npm 安裝Sharp

[英]I cant install sharp using npm

我無法使用sudo npm install sharp安裝Sharp庫。

終端output:

sharp@0.23.1 安裝 /Users/kozakiewicz/node_modules/sharp (node install/libvips && node install/dll-copy && prebuild-install) || (節點 gyp 重建 && 節點安裝/dll 復制)

info sharp Using cached /Users/kozakiewicz/.npm/_libvips/libvips-8.8.1-darwin-x64.tar.gz
ERR! sharp EACCES: permission denied, mkdir '/Users/kozakiewicz/node_modules/sharp/vendor'
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 ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/Users/kozakiewicz/node_modules/sharp/build'
gyp ERR! System Darwin 18.7.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/kozakiewicz/node_modules/sharp
gyp ERR! node -v v10.16.3
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
npm WARN enoent ENOENT: no such file or directory, open '/Users/kozakiewicz/package.json'
npm WARN gatsby-plugin-sass@2.1.14 requires a peer of gatsby@^2.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN gatsby-plugin-sass@2.1.14 requires a peer of node-sass@^4.9.0 but none is installed. You must install peer dependencies yourself.
npm WARN sass-loader@7.3.1 requires a peer of webpack@^3.0.0 || ^4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN gatsby-plugin-sharp@2.2.27 requires a peer of gatsby@^2.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN gatsby-source-contentful@2.1.36 requires a peer of gatsby@^2.0.33 but none is installed. You must install peer dependencies yourself.
npm WARN gatsby-source-filesystem@2.1.22 requires a peer of gatsby@^2.2.0 but none is installed. You must install peer dependencies yourself.
npm WARN gatsby-transformer-sqip@2.1.25 requires a peer of gatsby@^2.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN gatsby-transformer-sqip@2.1.25 requires a peer of gatsby-transformer-sharp@^2.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN sass-loader@7.1.0 requires a peer of webpack@^3.0.0 || ^4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN kozakiewicz No description
npm WARN kozakiewicz No repository field.
npm WARN kozakiewicz No README data
npm WARN kozakiewicz No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sharp@0.23.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.23.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!     /Users/kozakiewicz/.npm/_logs/2019-10-14T21_07_02_376Z-debug.log

使用 rm -rf node_modules 刪除所有依賴項,並刪除 /home/USER/.npm/_libvips/libvips-8.8.1-linux-x64.tar.gz 並重試應該可以解決。

這有幾個可能的原因,讓我印象深刻的是節點版本。

我將node --version設置為14.0.0 ,它應該與環境中設置的內容相同。

  1. 安裝nvm (節點版本管理器)
  2. 找到您需要使用的節點版本
  3. nvm use 10或將 10 替換為您的節點版本值。

從工作機器復制 libvips-8.8.1-linux-x64.tar.gz 並將其粘貼到 /home/USER/.npm/_libvips/ 解決了這個問題

也許您正在使用root用戶運行。

嘗試npm config -g set unsafe-perm true ,即使它有點危險

如果您使用 Ubuntu 試試這個

sudo apt-get update
sudo apt-get -y install libvips-dev
npm rebuild sharp
sudo npm install sharp

使用 sudo 運行您的命令,例如 sudo [您的命令]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM