类别: 建站技术

创建静态站点时报错npm ERR! Failed at the mozjpeg@7.0.0 postinstall script.

概述

使用Gatsby Starters模板(比如gatsby-starter-netlify-cms、gatsby-starter-ghost)创建gatsby站点时报错npm ERR! Failed at the mozjpeg@7.0.0 postinstall script. 该问题是由于gtihub网站国内无法访问导致。可以通过修改本地hosts文件或用翻墙软件解决该问题。

问题描述

通过命令gatsby new my-gatsby-project https://github.com/netlify-templates/gatsby-starter-netlify-cms创建站点时报以下错误,另外用其他模板(如gatsby-starter-ghost)创建站点时也报类似错误。报错详情如下:

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mozjpeg@7.0.0 postinstall: `node lib/install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the mozjpeg@7.0.0 postinstall 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:

 ERROR

Command failed with exit code 1: npm install
创建Gatsby站点时报错npm ERR! Failed at the mozjpeg@7.0.0 postinstall script.

解决方法

该问题是由于国内无法github.com和githubusercontent.com等资源网站导致。该问题的原理和解决方法与另外一篇博客一样,可先尝试修改本地hosts文件,添加github.com和githubusercontent.com等域名DNS信息,如果还是无法解决,就只能用翻墙软件了。详情解决方法见博客:npm安装包时报错npm ERR! Failed at the gifsicle@4.0.1 postinstall script

npm安装包报错ERR! Failed at the mozjpeg@7.0.0 postinstall script解决方法

扩展 – 小技巧

创建站点时,如果遇到npm安装包时报错,导致没有完全安装。可以看看站点文件夹内是否存在node_modules文件夹,如果有可以用命令gatsby develop启动站点,看看报错内容,哪个包缺失或不全,这时只需用npm安装该包即可,安装命令是:

D:\www\gatsby\2-site>cd node_modules
D:\www\gatsby\2-site\node_modules>npm install --save gatsby-plugin-sharp
gatsby develop报错Couldn’t find the “gatsby-plugin-sharp” plugin declared in

转载请注明:半亩方塘 » 创建静态站点时报错npm ERR! Failed at the mozjpeg@7.0.0 postinstall script.