解决 npm i node-sass@4.12.0 安装失败异常 npm i node-sass异常解决

解决 npm i node-sass@4.12.0 安装失败异常 npm i node-sass异常解决

  • [解决 npm i node-sass@4.12.0 安装失败异常 npm i node-sass异常解决](#解决 npm i node-sass@4.12.0 安装失败异常 npm i node-sass异常解决)

解决 npm i node-sass@4.12.0 安装失败异常 npm i node-sass异常解决

本地环境:node: 12.20.1

异常提示关键字:Python、C++、gyp编译问题

bash 复制代码
Traceback (most recent call last):
  File "D:\java-works\yzwl\temp\node_modules\node-gyp\gyp\gyp_main.py", line 16, in <module>
    sys.exit(gyp.script_main())
  File "D:\java-works\yzwl\temp\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 545, in script_main
    return main(sys.argv[1:])
  File "D:\java-works\yzwl\temp\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 538, in main
    return gyp_main(args)
  File "D:\java-works\yzwl\temp\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 514, in gyp_main
    options.duplicate_basename_check)
  File "D:\java-works\yzwl\temp\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 98, in Load
    generator.CalculateVariables(default_variables, params)
  File "D:\java-works\yzwl\temp\node_modules\node-gyp\gyp\pylib\gyp\generator\msvs.py", line 1916, in CalculateVariables
    generator_flags.get('msvs_version', 'auto'))
  File "D:\java-works\yzwl\temp\node_modules\node-gyp\gyp\pylib\gyp\MSVSVersion.py", line 434, in SelectVisualStudioVersion
    versions = _DetectVisualStudioVersions(version_map[version], 'e' in version)
KeyError: '2022'
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (D:\java-works\yzwl\temp\node_modules\node-gyp\lib\configure.js:345:16)
gyp ERR! stack     at ChildProcess.emit (events.js:314:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12)
gyp ERR! System Windows_NT 10.0.22631
gyp ERR! command "D:\\apps\\nvm\\nodejs\\node.exe" "D:\\java-works\\yzwl\\temp\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd D:\java-works\yzwl\temp\node_modules\node-sass
gyp ERR! node -v v12.20.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
Build failed with error code: 1
npm WARN temp@1.0.0 No description
npm WARN temp@1.0.0 No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.12.0 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@4.12.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

需要手动将 node-sass@4.12.0 依赖文件下载下来,存放到NPM缓存路径当中,这样执行 npm i的时候就直接可以从缓存里面安装,解决请求镜像源下载异常问题

node-sass@4.12.0对应的依赖下载地址: win32-x64-72_binding.node

默认的NPM缓存路径:C:\Users\用户\AppData\Roaming\npm-cache\

将依赖文件放到 npm-cache\node-sass\4.12.0当中

通过CMD查询具体本机的NPM缓存路径:

bash 复制代码
# 查看当前 npm 缓存路径
npm config get cache

最后执行安装node-sass查看是否成功

bash 复制代码
npm i node-sass@4.12.0
相关推荐
wflynn12 小时前
GitHub 今日推荐|rust-anything:录制真实输入输出,渐进式重写热点函数到 Rust
rust·开源·github·cli·claude-code·agent-skills
风笙9781 天前
[Rust] String 与 &str 详解
rust
风笙9781 天前
[Rust]复合类型
rust
风笙9781 天前
[Rust] 所有权与引用
rust
Kapaseker1 天前
最近用 Rust 写工具,我发现这 7 个库是真好用
rust
SomeOtherTime2 天前
第 11 讲(大结局):编译期元编程与零拷贝架构——卫生声明宏(macro_rules!)、过程宏 AST 手术刀与 Serde 零反射序列化的终极合龙
rust
SomeOtherTime2 天前
番外篇(第 12 讲):走向工业界深水区——从物理定律看 Rust 在真实工程中的“降维打击”与“阿喀琉斯之踵”
开发语言·rust
Kapaseker2 天前
Rust 桌面开发到底怎么选?先看这篇文章!
rust
奶油话梅糖2 天前
容器启停 2.5 毫秒:11 天 1,700 Star 的 Kiri,用一个 900 KB 的 PID 1 干掉了 runc 和 dockerd
前端·人工智能·rust
wflynn3 天前
GitHub 今日推荐|kiri:clone3 系统调用直达容器,2.5 毫秒启动无 runc 中间层
docker·rust·kubernetes·开源·github·containers