vue项目yarn初始化项目报错error D:\xxx\node_modules\node-sass;终极解决方案

解决 Yarn 初始化项目失败问题,因 node-sass 编译版本不匹配导致错误。通过配置 .npmrc 文件指定 sass_binary_site 和 registry 地址,并清理 node_modules、yarn.lock 和 package-lock.json 文件最终成功。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题:入职公司,接手项目yarn初始化项目一直失败崩溃啊!!!!!!!

报错内容:

error D:\xxx\xxx\node_modules\node-sass: Command failed.
Exit code: 1
Command: node scripts/build.js
Arguments:
Directory: D:\xxx\xxx\node_modules\node-sass
Output:
Binary found at D:\software\nodesass\win32-x64-72_binding.node
Testing binary
Binary has a problem: Error: The module '\\?\D:\software\nodesass\win32-x64-72_binding.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 64. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:717:18)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
gyp ERR! System Windows_NT 10.0.19042
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "D:\\xxx\\xxx\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd D:\xxx\xxx\node_modules\node-sass
gyp ERR! node -v v16.13.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok

提升node版本16.13和package.json里面"node-sass": “^4.14.1” 不匹配

然后就是安装node的版本控制工具nvm;用nvm安装对应的node版本
一顿操作猛如虎最后node版本安装了五六个还是没解决问题啊

网上博客都不靠谱啊!!!!

**

最后找到了终极解决方案

**

一、根目录创建 .npmrc 文件
二、在.npmrc文件里面写入 下面代码

sass_binary_site = https://npmmirror.com/mirrors/node-sass/
registry = https://registry.npmmirror.com/

三、然后删除之前拉取的文件

1、删除拉取的node_modules文件夹
2、删除yarn.lock文件(有yarn-log文件的一起删除)
3、删除package-lock.json文件

然后你就执行 yarn 或者 npm install 命令

静静的等待成功吧;爱你么么哒!!!!!!!

亲自测试有效;比网上介绍的换node版本或者node-sass版本简单有效

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码农有梦想

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值