解决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 这跟命令,也许问题就解决了

相关推荐
lastHertz4 天前
openskill 实战指南:像管理 npm 包一样管理你的 AI Skill
前端·人工智能·npm
qq_589666055 天前
npm install npm install -g @vue/cli 分别是什么意思以及安装路径
前端·vue.js·npm
Dreamboat-L6 天前
NVM的安装与使用(保姆级教程)
npm·node.js
无责任此方_修行中7 天前
踩坑实录:为什么 `pnpm run` 会偷偷帮你装依赖?—— 浅析 pnpm 与 npm run 的底层差异
javascript·后端·npm
特立独行的猫a7 天前
HarmonyOS鸿蒙PC三方库移植:Node.js 三方库鸿蒙 PC 移植指南
华为·node.js·node·harmonyos·三方库移植·鸿蒙pc
ShiXZ2139 天前
指令集-NPM 常用指令速查手册
前端·npm·node.js
是烨笙啊9 天前
从 npm 与 Bun 的选择看 AI 时代的“最佳实践”焦虑
前端·人工智能·npm
小杍随笔9 天前
【 .npmrc 终极配置指南:统一管理 npm/pnpm 缓存与全局目录,告别磁盘混乱】
前端·缓存·npm
ppshuX10 天前
npm-cli-造轮子初体验
npm
前端工作日常11 天前
我学习到的npx内部实现机制
npm