npm install 报错node-sass@4.13.0 postinstall:`node scripts/build.js` Failed at the node-sass@4.13.0

今天在安装谷歌开源的 squoosh ,npm install 报错node-sass@4.13.0 postinstall: node scripts/build.js Failed at the node-sass@4.13.0


今天在安装谷歌开源的 squoosh ,图像压缩的,本来只需要

Clone the repo, and:

1
2
npm install
npm run build

You can run the development server with:

1
npm start

就可以了,但是npm install就报错了。

npm install 报错node-sass@4.13.0 postinstall:node scripts/build.js Failed at the node-sass@4.13.0

具体错误为:

1
2
3
4
5
6
7
8
9
10
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.13.0 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@4.13.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:
npm ERR! C:\Users\12447\AppData\Roaming\npm-cache\_logs\2020-05-06T14_00_42_188Z-debug.log

解决方法

更改node-sass 的数据源设置,改为淘宝镜像即可

1
npm config set sass_binary_site=https://npm.taobao.org/mirrors/node-sass

然后重新安装

1
npm install

然后报错

1
2
3
4
5
6
7
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! squoosh@1.9.1 build: `webpack -p`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the squoosh@1.9.1 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

参考 stackoverflow 中大神的解决方法:

Step 1: $ npm cache clean --force

步骤1: $npm 清空缓存—- 强制

Step 2: Delete node_modules by $ rm -rf node_modules package-lock.json folder or delete it manually by going into the directory and right-click > delete / move to trash. Also, delete package-lock.json file too.

步骤2: 通过 $rm-rf 节点模块包锁删除节点模块。 Json 文件夹或手动删除它进入目录和右键单击删除 / 移动到垃圾桶。 另外,删除包锁。 还有 json 文件。

Step 3: npm install

步骤3: npm 安装

To start again, $ npm start

重新开始,$npm 开始

This worked for me. Hopes it works for you too.

这招对我管用希望对你也管用。

PS: Still if it is there, kindly check the error it is displaying in red and act accordingly. This error is specific to node.js environment. Happy Coding!!

Ps: 如果它还在,请检查它显示为红色的错误,并采取相应的行动。 此错误是特定于 node.js 环境的。 代码快乐!

leaning Cache and Node_module are not enough. Follow this steps:

清理 Cache 和 Node 模块是不够的。按照以下步骤操作:

  • npm cache clean --force
  • delete 删除node_modules folder 文件夹
  • delete 删除package-lock.json file 文件
  • npm install

It works for me like this.

这对我来说是这样的。

Change access in node_modules directory

更改节点模块目录中的访问权限

1
chmod -R a+rwx ./node_modules 

I resolve this error running following code

我按照下面的代码来解决这个错误

1
npm cache clean

then delete node_modules directory from my project structure manually or with following command

然后手动或使用以下命令从项目结构中删除节点模块目录

1
rm -rf node_modules

After That install dependencies again using

在这之后,再次使用

1
npm install

Delete node_modules and package-lock.json, and then run npm install. It worked perfectly here(run command below inside project root):

删除节点模块和 package-lock. json,然后运行 npm install:

1
rm -rf node_modules && rm ./package-lock.json && npm install



参考:

https://stackoverflow.com/questions/42308879/npm-err-code-elifecycle