关于安装node-sass以及sass-loader时遇到的错误问题

npm WARN deprecated @npmcli/move-file@1.1.2: This functionality has been moved to @npmcli/fs
npm ERR! code 1
npm ERR! path D:\Code\my-project\node_modules\node-sass
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node scripts/build.js
npm ERR! Building: D:\Program Files\nodejs\node.exe D:\Code\my-project\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp verb cli [
npm ERR! gyp verb cli   'D:\\Program Files\\nodejs\\node.exe',
npm ERR! gyp verb cli   'D:\\Code\\my-project\\node_modules\\node-gyp\\bin\\node-gyp.js',
npm ERR! gyp verb cli   'rebuild',
npm ERR! gyp verb cli   '--verbose',
npm ERR! gyp verb cli   '--libsass_ext=',
npm ERR! gyp verb cli   '--libsass_cflags=',
npm ERR! gyp verb cli   '--libsass_ldflags=',
npm ERR! gyp verb cli   '--libsass_library='
npm ERR! gyp verb cli ]
npm ERR! gyp info using node-gyp@8.4.1
npm ERR! gyp info using node@18.15.0 | win32 | x64
npm ERR! gyp verb command rebuild []
npm ERR! gyp verb command clean []
npm ERR! gyp verb clean removing "build" directory
npm ERR! gyp verb command configure []
npm ERR! gyp verb find Python Python is not set from command line or npm configuration
npm ERR! gyp verb find Python Python is not set from environment variable PYTHON
npm ERR! gyp verb find Python checking if "python3" can be used
npm ERR! gyp verb find Python - executing "python3" to get executable path
npm ERR! gyp verb find Python - "python3" is not in PATH or produced an error
npm ERR! gyp verb find Python checking if "python" can be used
npm ERR! gyp verb find Python - executing "python" to get executable path
npm ERR! gyp verb find Python - executable path is "C:\Program Files\python\python.exe"
npm ERR! gyp verb find Python - executing "C:\Program Files\python\python.exe" to get version
npm ERR! gyp verb find Python - version is "3.8.6"
npm ERR! gyp info find Python using Python version 3.8.6 found at "C:\Program Files\python\python.exe"
npm ERR! gyp verb get node dir no --target version specified, falling back to host node version: 18.15.0
npm ERR! gyp verb command install [ '18.15.0' ]
npm ERR! gyp verb install input version string "18.15.0"
npm ERR! gyp verb install installing version: 18.15.0
npm ERR! gyp verb install --ensure was passed, so won't reinstall if already installed
npm ERR! gyp verb install version not already installed, continuing with install 18.15.0
npm ERR! gyp verb ensuring nodedir is created C:\Users\Administrator\AppData\Local\node-gyp\Cache\18.15.0
npm ERR! gyp verb created nodedir C:\Users\Administrator\AppData\Local\node-gyp
npm ERR! gyp http GET https://nodejs.org/download/release/v18.15.0/node-v18.15.0-headers.tar.gz
npm ERR! gyp WARN install got an error, rolling back install
npm ERR! gyp verb command remove [ '18.15.0' ]
npm ERR! gyp verb remove using node-gyp dir: C:\Users\Administrator\AppData\Local\node-gyp\Cache
npm ERR! gyp verb remove removing target version: 18.15.0
npm ERR! gyp verb remove removing development files for version: 18.15.0
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack FetchError: request to https://nodejs.org/download/release/v18.15.0/node-v18.15.0-headers.tar.gz failed, reason: connect ETIMEDOUT 104.20.22.46:443
npm ERR! gyp ERR! stack     at ClientRequest.<anonymous> (D:\Code\my-project\node_modules\minipass-fetch\lib\index.js:110:14)
npm ERR! gyp ERR! stack     at ClientRequest.emit (node:events:513:28)
npm ERR! gyp ERR! stack     at TLSSocket.socketErrorListener (node:_http_client:502:9)
npm ERR! gyp ERR! stack     at TLSSocket.emit (node:events:525:35)
npm ERR! gyp ERR! stack     at emitErrorNT (node:internal/streams/destroy:151:8)
npm ERR! gyp ERR! stack     at emitErrorCloseNT (node:internal/streams/destroy:116:3)
npm ERR! gyp ERR! System Windows_NT 10.0.19041
npm ERR! gyp ERR! command "D:\\Program Files\\nodejs\\node.exe" "D:\\Code\\my-project\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags
=" "--libsass_library="
npm ERR! gyp ERR! cwd D:\Code\my-project\node_modules\node-sass
npm ERR! gyp ERR! node -v v18.15.0
npm ERR! gyp ERR! node-gyp -v v8.4.1
npm ERR! gyp ERR! not ok
npm ERR! Build failed with error code: 1

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Local\npm-cache\_logs\2023-04-19T07_03_12_270Z-debug-0.log

以上是错误日志。

首先根据错误信息,我发现是我本地没有安装python导致的,于是我就去官网下载了最新的python。

https://www.python.org/downloads/release/python-3113/

下载安装完成后,找到python安装目录,如果在安装时没有选择自动添加到系统环境的path路径中,需要自己手动安装。
运行以下指令,将python与npm绑定起来

npm config edit   //此命令会打开一个记事本程序,里面是npm的配置信息

在配置信息文件里面的任意行加上一个配置项

python=你的python的安装目录\python.exe

接下来,当你再次安装node-sass时

npm install node-sass@7.0.1 --save-dev

还是会报错的话,那就需要设置 msvs_version 。这个配置项主要就是node-gyp在build的时候会用到,但是这个需要我们本地安装Microsoft Visual Studio 编辑器。假设,我们安装了\Microsoft Visual Studio2019,那我们就可以这么设置。

npm config edit
//然后添加配置项
msvs_version=2019

然后,就能安装成功啦!

其中最麻烦的就是安装Microsoft Visual Studio。

最后,注意一点,在安装node-sass以及sass-loader时,它们的版本必须要一一对应,可以按照我的安装命令进行安装

1) npm install node-sass@7.0.1 --save-dev
2) npm install sass-loader@7.3.1 --save-dev
3) npm install
4) npm run dev
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

就叫我菜菜吧

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

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

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

打赏作者

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

抵扣说明:

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

余额充值