【问题标题】:installing npm modules on ubuntu gives me an error在 ubuntu 上安装 npm 模块给我一个错误
【发布时间】:2019-04-21 03:24:19
【问题描述】:

当我尝试安装名为 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 也有类似的问题。我已尝试安装所有依赖项和开发依赖项,但重试无济于事。

【问题讨论】:

标签: node.js ubuntu npm


【解决方案1】:

问题似乎是您没有权限。

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 上遇到的问题的根源

【讨论】:

    【解决方案2】:

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

    sudo npm install --unsafe-perm -g sharp
    

    Reference.

    【讨论】:

      【解决方案3】:

      sudo npm install --unsafe-perm=true --allow-root

      对于示例:sudo npm install -g cordova-res --unsafe-perm=true --allow-root

      【讨论】:

        【解决方案4】:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-04-03
          • 2012-03-02
          • 1970-01-01
          • 2011-11-12
          • 2011-10-23
          • 2014-08-24
          • 1970-01-01
          • 2019-03-08
          相关资源
          最近更新 更多