【问题标题】:Can't install Sharp无法安装夏普
【发布时间】:2019-06-21 22:12:48
【问题描述】:

运行sudo npm i sharp --save 时出现以下错误:

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

info sharp Using cached /home/ronny/.npm/_libvips/libvips-8.7.0-linux-x64.tar.gz
ERR! sharp EACCES: permission denied, mkdir '/home/server/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 '/home/server/node_modules/sharp/build'
gyp ERR! System Linux 4.18.0-13-generic
gyp ERR! command "/usr/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/server/node_modules/sharp
gyp ERR! node -v v8.11.4
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
npm WARN server@1.0.0 No description
npm WARN server@1.0.0 No repository field.

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!     /home/ronny/.npm/_logs/2019-01-28T20_33_46_476Z-debug.log

我在另一台机器上运行了相同的项目,并且安装工作完美无缺。但是在我的另一台机器上(都运行 Linux Ubuntu)我遇到了上述错误。

我找不到任何解决此错误的方法。这就是我在这里寻求帮助的原因。

【问题讨论】:

  • gyp 错误!堆栈错误:EACCES:权限被拒绝,mkdir '/home/server/node_modules/sharp/build' (SUDO?)
  • 我输入的命令是sudo,所以我应该有权限

标签: node.js npm sharp


【解决方案1】:

晚了,但我要告诉你什么对我有用。如果您之前安装了任何与Sharp 完全相同的依赖项,请从您的Package.json 文件中删除该dependency,然后运行

npm install sharp

【讨论】:

  • 当我开始从事一个大约 3 岁的项目时,我在多个操作系统/发行版上遇到了一个问题。这个解决方案解决了我在 MacOS BigSur、Windows 11 和 CentOS 7.9 上的问题。附带说明一下,这个问题可能是由缺少 python 3 引起的。
  • 如果有帮助我很高兴。我在 NodeJs(Javascript) 中遇到了这个问题
【解决方案2】:

尝试使用 yarn 而不是 npm,它对我有用(docker,官方节点映像 16.x)

yarn add sharp

【讨论】:

    【解决方案3】:

    npm install --arch=x64 --platform=linux sharp 为我工作

    取自:https://github.com/lovell/sharp/issues/2128#issuecomment-600232917

    我使用的是 M1 mac

    【讨论】:

      【解决方案4】:

      最简单的方法是:

      brew uninstall vips
      

      然后:

      npm install
      

      【讨论】:

        【解决方案5】:

        对于 Apple M1 brew install vips 然后 npm install --unsafe-perm

        如果它不能解决您的问题,请在 similar issue 中查找更多信息

        • xcode-select --install
        • brew install gcc
        • brew 重新安装 vips
        • 酿造信息贵宾
        • npm 我

        【讨论】:

          【解决方案6】:

          我的 Apple M1 遇到了同样的问题,我运行了下一个命令:

          • 我删除了 node_modules
          • 我删除了 package-lock.json
          • 运行:brew install vips
          • 运行:npm install --unsafe-perm

          它有效

          【讨论】:

            【解决方案7】:

            Node v13.14.0+的问题,问题会解决的

            npm install sharp@0.23.2 
            

            如果您使用的是sharp 0.22.1,您应该将Node版本降级到> = 10.0.0

            【讨论】:

              【解决方案8】:

              所以首先错误显示权限被拒绝。 使用
              sudo
              安装它 当您在sharp documentation 中使用sudo 时!它说你必须使用
              npm install --unsafe-perm

              我会推荐:

              • 转到/home/ronny/.npm/_libvips/libvips-8.7.0-linux-x64.tar.gz(在您的错误代码中)
              • 删除文件:libvips-8.7.0-linux-x64.tar.gz
              • 在您的终端类型中:npm install --unsafe-perm(这将安装已删除的库)
              • npm install sharp

              那我觉得我应该好好工作。这些步骤解决了我的问题,我遇到了同样的问题。 希望能帮助到你。谢谢。

              【讨论】:

                【解决方案9】:

                删除 package-lock.jsonnode_modules

                然后尝试安装软件包 npm install

                为我工作。

                【讨论】:

                • 它对我有用,我的节点版本 v14.17.0 npm 版本 7.17.0 尖锐版本 "^0.27.0"
                【解决方案10】:

                在 Windows 上运行 npx create-strapi-app my-project --quickstart 并得到相同的错误,必须从 Visual Studio 安装 C++ 进行桌面开发,它工作正常。

                【讨论】:

                  【解决方案11】:

                  我已经通过降级node version to 10.0.0 解决了这个错误。真的好用!

                  【讨论】:

                  • 在我的情况下,从 v16.13.0 降级到 v14.16.1 可以解决问题
                  【解决方案12】:

                  这对我有用。 npm install --unsafe-perm

                  请参考以下讨论 https://github.com/lovell/sharp/issues/1627#issuecomment-477109851

                  【讨论】:

                  • 我还发现this blogpost 有助于理解其原因。简而言之,npm 在安装模块时会尝试切换到用户帐户,因为以 root 身份安装的模块只能由 root 进程使用。以 root 身份运行常规进程被认为是不安全的,因此使用了参数名称。
                  猜你喜欢
                  • 1970-01-01
                  • 1970-01-01
                  • 2019-09-29
                  • 2019-06-22
                  • 2015-01-29
                  • 2020-12-14
                  • 1970-01-01
                  • 2012-01-23
                  • 1970-01-01
                  相关资源
                  最近更新 更多