NodeJS 在ubuntu上安装npm模块给我一个错误

fumotvh3  于 2023-03-01  发布在  Node.js
关注(0)|答案(4)|浏览(142)

当我尝试安装一个叫做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上也有类似的问题。我试过安装所有的依赖项和dev-dependency,但没有成功。

yebdmbv4

yebdmbv41#

我也遇到过这个问题,我可以通过以下命令解决它:

sudo npm install --unsafe-perm -g sharp

参考。

bmp9r5qi

bmp9r5qi2#

sudo chown -R $USER ~/.npm对我很有效,因为这显然是用户对此文件夹的访问问题。

wfveoks0

wfveoks03#

问题似乎是您没有权限。

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从另一个发行版还是这是一个新鲜的安装?我问这个,因为有时有冲突时升级.它总是最好的做一个新鲜的操作系统安装时,这是一个新的发行版.
这是您在your other question上遇到的问题的根源

6ioyuze2

6ioyuze24#

sudo npm安装--不安全权限=true --允许root
例如:sudo npm安装-g cordova-res --不安全权限=真--允许根

相关问题