vue2 安装 sass-loader和node-sass 异常 Binary has a problem: Error和gyp ERR! stack Error: connect ETIMEDOUT

正常安装 sass-loader,命令:npm install sass-loader --save-dev ,安装成功,没有异常,只是警告,如下图:

打开package.json 查看依赖正常,如下图: 

当安装 node-sass,命令:npm install node-sass --save-dev ,如下图:

安装过程中出现异常:

> node-sass@9.0.0 postinstall E:\VueProject\Vue2\yeb\node_modules\node-sass
> node scripts/build.js

Binary found at E:\VueProject\Vue2\yeb\node_modules\node-sass\vendor\win32-x64-83\binding.node
Testing binary
Binary has a problem: Error: \\?\E:\VueProject\Vue2\yeb\node_modules\node-sass\vendor\win32-x64-83\binding.node is not a valid Win32 application.
\\?\E:\VueProject\Vue2\yeb\node_modules\node-sass\vendor\win32-x64-83\binding.node
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1173:18)
    at Module.load (internal/modules/cjs/loader.js:979:32)
    at Function.Module._load (internal/modules/cjs/loader.js:819:12)
    at Module.require (internal/modules/cjs/loader.js:1003:19)
    at require (internal/modules/cjs/helpers.js:107:18)
    at module.exports (E:\VueProject\Vue2\yeb\node_modules\node-sass\lib\binding.js:19:10)   
    at Object.<anonymous> (E:\VueProject\Vue2\yeb\node_modules\node-sass\lib\index.js:13:35) 
    at Module._compile (internal/modules/cjs/loader.js:1114:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
    at Module.load (internal/modules/cjs/loader.js:979:32) {
  code: 'ERR_DLOPEN_FAILED'
}
Building the binary locally
Building: C:\NodeJs\14.21.3\node.exe E:\VueProject\Vue2\yeb\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=

仔细查看后,主要是这句: 

Binary has a problem: Error: \\?\E:\VueProject\Vue2\yeb\node_modules\node-sass\vendor\win32-x64-83\binding.node is not a valid Win32 application. 

想到上面安装没有指定版本是不是,默认版本太高,本文使用的node版本是14.21.3,如下图:

版本参考,具体以官网更新为准:

 在VUE2.0项目中我们普遍使用nodeJS(版本):14 ,  node-sass(版本):4.14+, webpack

 在VUE3.0项目中我们普遍是nodeJS(版本):最新长期稳定版本16+,  node-sass(版本):7+,vite

 查看版本:

node -v 

node-sass 请直接编辑工具搜索node-sass查看版本号 

经过上面分析卸载 sass-loader,命令:npm uninstall sass-loader :

卸载后,安装指定版本 sass-loader,命令:npm install sass-loader@10.1.1 --save-dev,如下图: 

安装 node-sass ,命令:npm install node-sass@5.0.0 --save-dev

安装过程中又出现一个异常,如下图: 

异常信息如下: 

第一部分: 

gyp verb remove removing target version: 14.21.3
gyp verb remove removing development files for version: 14.21.3
gyp ERR! configure error
gyp ERR! stack Error: connect ETIMEDOUT 104.20.22.46:443
gyp ERR! stack     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1159:16)
gyp ERR! System Windows_NT 10.0.22621
gyp ERR! command "C:\\NodeJs\\14.21.3\\node.exe" "E:\\VueProject\\Vue2\\yeb\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd E:\VueProject\Vue2\yeb\node_modules\node-sass
gyp ERR! node -v v14.21.3
gyp ERR! node-gyp -v v7.1.2
gyp ERR! not ok 

第二部分: 

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@5.0.0 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@5.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:
npm ERR!     C:\Users\admin\AppData\Roaming\npm-cache\_logs\2024-09-12T02_31_16_062Z-debug.log

解决方案:

npm install --production --unsafe-perm=true --allow-root

再次执行安装node-sass,命令:npm install node-sass@5.0.0 --save-dev 

安装成功,如下图: 

  • 8
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值