簡體   English   中英

在 ubuntu 上安裝 npm 模塊給我一個錯誤

[英]installing npm modules on ubuntu gives me an error

當我嘗試安裝名為sharp的npm包時出現以下錯誤。

sudo npm install -g sharp

> sharp@0.21.0 install /usr/local/lib/node_modules/sharp
> (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)

info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.7.0/libvips-8.7.0-linux-x64.tar.gz
ERR! sharp EACCES: permission denied, open '/usr/local/lib/node_modules/sharp/19229-libvips-8.7.0-linux-x64.tar.gz'
ERR! sharp Please see http://sharp.pixelplumbing.com/page/install
gyp WARN EACCES user "root" does not have permission to access the dev dir "/home/areahints/.node-gyp/8.10.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/sharp/.node-gyp"
gyp WARN install got an error, rolling back install
gyp WARN install got an error, rolling back install
gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/sharp/.node-gyp'
gyp ERR! System Linux 4.15.0-39-lowlatency
gyp ERR! command "/usr/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/sharp
gyp ERR! node -v v8.10.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sharp@0.21.0 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.0 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!     /home/areahints/.npm/_logs/2018-11-18T16_14_58_685Z-debug.log

在沒有 sudo 的情況下運行相同的代碼會引發不同的錯誤

npm install -g sharp
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!  { Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!   stack: 'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules' }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).

我對 node-expat、iconv 和 libxmljs 有類似的問題。 我嘗試安裝所有依賴項和開發依賴項,但重試無濟於事。

我也遇到過這個問題。 我能夠通過這個命令解決它:

sudo npm install --unsafe-perm -g sharp

參考。

看起來問題是您沒有權限。

sudo chown -R areahints /home/areahints && sudo chmod -R 777 /home/areahints

對任何它說您沒有權限的目錄重復此步驟 ^

sudo apt-get update –fix-missing
sudo dpkg –configure -a
sudo apt-get install -f

這應該有助於修復損壞的軟件包並安裝缺少的依賴項 ^

sudo apt-get update
sudo apt-get upgrade
sudo apt-get update
sudo apt-get autoremove

這應該在你安裝任何東西之前完成,也應該在 ^

您是從其他發行版升級到 18.04 還是全新安裝? 我問這個是因為有時升級時會發生沖突。 當它是一個新的發行版時,最好進行全新的操作系統安裝。

這是您在其他問題上遇到的問題的根源

須藤 npm install --unsafe-perm=true --allow-root

例如: sudo npm install -g cordova-res --unsafe-perm=true --allow-root

sudo chown -R $USER ~/.npm為我工作。

暫無
暫無

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

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