解决npm install报错: No module named gyp

今天运行一个以前vue项目,启动时报错如下:

ERROR Failed to compile with 1 error上午10:19:33

error in ./src/App.vue?vue&type=style&index=0&lang=scss&

Syntax Error: Error: Missing binding D:\javacode\Springboot-MiMall-RSA\VueFront\node_modules\_node-sass@4.14.1@nod e-sass\vendor\win32-x64-83\binding.node

Node Sass could not find a binding for your current environment: Windows 64-bit with Node.js 14.x

Found bindings for the following environments:

  • Windows 64-bit with Node.js 12.x

This usually happens because your environment has changed since running `npm install`.

Run `npm rebuild node-sass` to download the binding for your current environment.

大致意思是:因为我把node 12升级成了14, Node Sass库的兼容性出问题了。

我当时没多想,就把node_modules目录删除了,重新运行npm install,结果报错:

No module named gyp

网上查了一些资料说解决办法如下:

1. 指定python2.7路径:npm config set python python2.7

  1. 运行:npm install --no-optional

以上参考:https://spin.atomicobject.com/2019/03/27/node-gyp-windows/

但是两个方法都试过了,全部无效。

后来在一篇文章:node-sass,sass-loader,node-gyp,node报错,版本对应问题

找到解决办法: 原来node版本跟node-sass有对应关系:

我之前的node-sass版本是4.12.0,把它修改成4.14.1 ,然后重新npm install就解决问题了

此时我突然想起我启动时第一次的报错:

RSA\VueFront\node_modules\_node-sass@4.14.1@nod e-sass\vendor\win32-x64-83\binding.node

Node Sass could not find a binding for your current environment: Windows 64-bit with Node.js 14.x

Found bindings for the following environments:

  • Windows 64-bit with Node.js 12.x

This usually happens because your environment has changed since running `npm install`.

Run `npm rebuild node-sass` to download the binding for your current environment.

上面的提示其实写清楚了需要node-sass@4.14.1来匹配Node.js 14.x,建议修复命令:npm rebuild node-sass来修复。

我在想如果一开始我就运行:npm rebuild node-sass 这跟命令,也许问题就解决了

相关推荐
Patrick_Wilson2 天前
悬浮提示从哪来:LSP、tsserver 与 .d.ts
typescript·npm·前端工程化
Patrick_Wilson2 天前
npm 的 bin 如何接到 npm run 与 npx
npm·node.js·前端工程化
Patrick_Wilson2 天前
import 之后发生了什么:package.json、解析与安装产物
npm·node.js·前端工程化
Patrick_Wilson2 天前
npm 里 SemVer 和 dist-tag 如何决定装哪一版
npm·node.js·前端工程化
zttbee2 天前
npm install卡顿
前端·npm·node.js
Flynt3 天前
axios 被投毒半年后,我把 npm 的"安全防线"实测了一遍:最信任的 SHA512 是安慰剂
前端·npm·node.js
天若有情6734 天前
POT规范|一套个人自研NPM包本地生命周期管理体系
npm·包管理·前端工程化·个人开源·工程规范·pot规范
Eloudy4 天前
全文 - Learning Exact NVIDIA SASS Encoders with [特殊字符]₂ Linear Algebra
sass·gpu
lpfasd1235 天前
node-sass 停止维护!老项目迁移 Dart Sass 完整教程
前端·rust·sass
小天源5 天前
智叟云集定时采集与消息推送架构——实现可恢复的订阅通知流程
架构·sass·权限管理·多租户·服务商 api·ai采集