14

运行时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)上,我遇到了上述错误。

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

4

12 回答 12

29

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

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

于 2019-05-13T08:21:57.360 回答
5

Node v13.14.0+的问题,问题就解决了

npm install sharp@0.23.2 

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

于 2021-03-07T16:35:18.847 回答
5

最简单的方法是:

brew uninstall vips

进而:

npm install
于 2021-06-11T15:29:40.970 回答
4

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

于 2019-12-23T11:22:51.230 回答
4

删除package-lock.jsonnode_modules

然后尝试安装npm install

为我工作的包。

于 2020-06-22T12:35:37.200 回答
3

那么对于Apple M1 brew install vipsnpm install --unsafe-perm

如果它不能解决您的问题,请在此类似问题中找到更多信息

  • xcode-选择--安装
  • 酿造安装 gcc
  • brew重新安装vips
  • 酿造信息贵宾
  • npm 我
于 2021-02-01T11:37:15.207 回答
2

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

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

我正在使用M1 mac

于 2021-08-13T07:34:42.733 回答
1

所以首先错误说权限被拒绝。
sudo
当您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

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

于 2020-10-02T05:45:23.467 回答
1

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

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

它有效

于 2021-03-25T05:48:24.923 回答
1

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

yarn add sharp
于 2021-09-20T05:36:59.987 回答
1

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

npm install sharp
于 2021-10-29T20:59:44.990 回答
0

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

于 2020-06-20T08:58:02.487 回答