Gatsby new 安装锐包失败
Posted
技术标签:
【中文标题】Gatsby new 安装锐包失败【英文标题】:Gatsby new fails to install the sharp package and breaks 【发布时间】:2020-03-14 02:35:17 【问题描述】:我无法启动 gatsby 入门项目。 new
命令进程在初始化过程中发生故障,并导致错误和不可编译的项目。
命令如下:
> gatsby new gatsby-test
以下过程开始,在npm install
期间尝试安装锐利包时失败。
info Creating new site from git:
Cloning into 'gatsby-test'...
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 2309 (delta 4), reused 10 (delta 4), pack-reused 2299
Receiving objects: 100% (2309/2309), 12.62 MiB | 7.98 MiB/s, done.
Resolving deltas: 100% (1487/1487), done.
success Created starter directory layout
info Installing packages...
> sharp@0.23.2 install /home/developer/projects/gatsby-test/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.8.1/libvips-8.8.1-linux-x64.tar.gz
fs.js:114
throw err;
^
Error: EACCES: permission denied, copyfile '/tmp/1890-libvips-8.8.1-linux-x64.tar.gz' -> '/home/developer/.npm/_libvips/libvips-8.8.1-linux-x64.tar.gz'
at Object.copyFileSync (fs.js:1728:3)
at WriteStream.<anonymous> (/home/developer/projects/gatsby-test/node_modules/sharp/install/libvips.js:104:16)
at WriteStream.emit (events.js:198:13)
at lazyFs.close (internal/fs/streams.js:207:14)
at FSReqWrap.args [as oncomplete] (fs.js:140:20)
make: Entering directory '/home/developer/projects/gatsby-test/node_modules/sharp/build'
TOUCH Release/obj.target/libvips-cpp.stamp
CXX(target) Release/obj.target/sharp/src/common.o
In file included from ../src/common.cc:25:0:
/usr/include/vips/vips8:35:10: fatal error: glib-object.h: No such file or directory
#include <glib-object.h>
^~~~~~~~~~~~~~~
compilation terminated.
sharp.target.mk:129: recipe for target 'Release/obj.target/sharp/src/common.o' failed
make: *** [Release/obj.target/sharp/src/common.o] Error 1
make: Leaving directory '/home/developer/projects/gatsby-test/node_modules/sharp/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack at ChildProcess.emit (events.js:198:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Linux 4.15.0-70-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/developer/projects/gatsby-test/node_modules/sharp
gyp ERR! node -v v10.17.0
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted "os":"darwin","arch":"any" (current: "os":"linux","arch":"x64")
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.2 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted "os":"darwin","arch":"any" (current: "os":"linux","arch":"x64")
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sharp@0.23.2 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.23.2 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/developer/.npm/_logs/2019-11-18T16_45_16_026Z-debug.log
ERROR
Command failed with exit code 1: npm install
Error: Command failed with exit code 1: npm install
- error.js:56 makeError
[lib]/[gatsby-cli]/[execa]/lib/error.js:56:11
- index.js:114 handlePromise
[lib]/[gatsby-cli]/[execa]/index.js:114:26
- next_tick.js:68 process._tickCallback
internal/process/next_tick.js:68:7
知道这里发生了什么吗?我看到过去sharp
存在一些问题,但现在这应该是一个已解决且已解决的问题。我在这里错过了什么?
【问题讨论】:
gatsby 项目维护者推荐yarn
用于构建项目。 npm
经常导致这些无法解释的构建错误。我知道您应该选择包管理器。根据我的经验,自从我使用了 yarn,我再也没有遇到这些错误了。
@EliteRaceElephant 但是所有的文档教程和示例都是用npm完成的,是yarn和官方推荐的吗?
我也通过从 npm 切换到 yarn 解决了这个问题。
【参考方案1】:
下面一行:
Error: EACCES: permission denied, copyfile '/tmp/1890-libvips-8.8.1-linux-x64.tar.gz' -> '/home/developer/.npm/_libvips/libvips-8.8.1-linux-x64.tar.gz'
建议您将 tmp 文件移动到用户本地 .npm 目录时出现权限错误。如果不了解有关哪个用户运行命令等的更多上下文,很难说出为什么会这样。
下面一行:
fatal error: glib-object.h: No such file or directory
建议您没有正确安装 sharp
或 vips
。
npm install sharp
对于 Ubuntu:
sudo apt-get install -y libvips-tools
Mac 版:
brew update vips
对于archlinux/manjaro:
sudo pacman -S libvips
【讨论】:
我已经安装了它,运行sudo apt-get install -y libvips-tools
确认它。问题仍然存在。 `
sharp
怎么样?测试npm view sharp version
但是sharp
应该全局安装吗? gatsby new <dir>
期望目录不存在。如何安装任何 npm 模块?
另外,试试sudo gatsby new gatsby-test
,看看会发生什么。如果它运行没有错误,它看起来是一个权限错误,如果是这种情况,我会冒险猜测这是因为使用 sudo
安装 gatsby(例如,sudo npm i -g gatsby
)
npm view sharp version
输出:0.23..3
【参考方案2】:
您可以通过在终端中运行以下命令来解决此问题...
rm -rf /Users/username/.npm/_libvips
brew install vips
rm -rf node_modules
npm install
【讨论】:
【参考方案3】:为了解决这个问题,我跑了:
rm -rf node_modules
yarn cache clean
yarn add --dev yarn-upgrade-all
npx yarn-upgrade-all
然后,当我运行命令升级所有包时,我重新安装了从 package.json 中删除的所有必要包。
之后,我跑了gatsby build
和gatsby develop
【讨论】:
【参考方案4】:我遇到了同样的问题。我通过手动下载包并粘贴来解决它
从https://github.com/lovell/sharp-libvips/releases/download/v8.8.1/libvips-8.8.1-linux-x64.tar.gz下载libvips
将 lib 复制到 .npm 文件夹中
sudo cp libvips-8.8.1-linux-x64.tar.gz /home/[YOURNAME]/.npm/_libvips/
删除损坏的 gatsby-test 文件夹
运行
盖茨比新盖茨比测试
再次
【讨论】:
以上是关于Gatsby new 安装锐包失败的主要内容,如果未能解决你的问题,请参考以下文章