npm 安装sass依赖出错:Could not find any Visual Studio installation to use ,VS could not use PowerShell to

node 安装sass时出错

1.gyp verb find VS could not use PowerShell to find Visual Studio 2017 or newer.
2.not looking for VS2013 as it is only supported up to Node.js 8

主要问题:

说啥找不到 Visual Studio,然后叫你安装Visual Studio。

gyp verb find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details
gyp verb find VS looking for Visual Studio 2015
gyp verb find VS - not found
gyp verb find VS not looking for VS2013 as it is only supported up to Node.js 8
....
....
gyp ERR! find VS You need to install the latest version of Visual Studio
gyp ERR! find VS including the "Desktop development with C++" workload.

错误日志:

Exit code: 1
Command: node scripts/build.js
Arguments:
Directory: C:\WINDOWS\system32\node_modules\node-sass
Output:
Building: D:\Program Files\nodejs\node.exe C:\WINDOWS\system32\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli   'D:\\Program Files\\nodejs\\node.exe',
gyp verb cli   'C:\\WINDOWS\\system32\\node_modules\\node-gyp\\bin\\node-gyp.js',
gyp verb cli   'rebuild',
gyp verb cli   '--verbose',
gyp verb cli   '--libsass_ext=',
gyp verb cli   '--libsass_cflags=',
gyp verb cli   '--libsass_ldflags=',
gyp verb cli   '--libsass_library='
gyp verb cli ]
gyp info using node-gyp@8.4.1
gyp info using node@16.16.0 | win32 | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb find Python checking Python explicitly set from command line or npm configuration
gyp verb find Python - "--python=" or "npm config get python" is "D:\python"
gyp verb find Python - executing "D:\python" to get executable path
gyp verb find Python - "D:\python" is not in PATH or produced an error
gyp verb find Python Python is not set from environment variable PYTHON
gyp verb find Python checking if "python3" can be used
gyp verb find Python - executing "python3" to get executable path
gyp verb find Python - "python3" is not in PATH or produced an error
gyp verb find Python checking if "python" can be used
gyp verb find Python - executing "python" to get executable path
gyp verb find Python - executable path is "D:\python\python.exe"
gyp verb find Python - executing "D:\python\python.exe" to get version
gyp verb find Python - version is "3.9.9"
gyp info find Python using Python version 3.9.9 found at "D:\python\python.exe"
gyp verb get node dir no --target version specified, falling back to host node version: 16.16.0
gyp verb command install [ '16.16.0' ]
gyp verb install input version string "16.16.0"
gyp verb install installing version: 16.16.0
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version is already installed, need to check "installVersion"
gyp verb got "installVersion" 9
gyp verb needs "installVersion" 9
gyp verb install version is good
gyp verb get node dir target node version installed: 16.16.0
gyp verb build dir attempting to create "build" dir: C:\WINDOWS\system32\node_modules\node-sass\build
gyp verb build dir "build" dir needed to be created? Yes
gyp verb find VS msvs_version not set from command line or npm config
gyp verb find VS VCINSTALLDIR not set, not running in VS Command Prompt
gyp verb find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details
gyp verb find VS looking for Visual Studio 2015
gyp verb find VS - not found
gyp verb find VS not looking for VS2013 as it is only supported up to Node.js 8
gyp ERR! find VS
gyp ERR! find VS msvs_version not set from command line or npm config
gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details
gyp ERR! find VS looking for Visual Studio 2015
gyp ERR! find VS - not found
gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
gyp ERR! find VS
gyp ERR! find VS **************************************************************
gyp ERR! find VS You need to install the latest version of Visual Studio
gyp ERR! find VS including the "Desktop development with C++" workload.
gyp ERR! find VS For more information consult the documentation at:
gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
gyp ERR! find VS **************************************************************
gyp ERR! find VS
gyp ERR! configure error
gyp ERR! stack Error: Could not find any Visual Studio installation to use
gyp ERR! stack     at VisualStudioFinder.fail (C:\WINDOWS\system32\node_modules\node-gyp\lib\find-visualstudio.js:122:47)
gyp ERR! stack     at C:\WINDOWS\system32\node_modules\node-gyp\lib\find-visualstudio.js:75:16
gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (C:\WINDOWS\system32\node_modules\node-gyp\lib\find-visualstudio.js:363:14)
gyp ERR! stack     at C:\WINDOWS\system32\node_modules\node-gyp\lib\find-visualstudio.js:71:14
gyp ERR! stack     at C:\WINDOWS\system32\node_modules\node-gyp\lib\find-visualstudio.js:384:16
gyp ERR! stack     at C:\WINDOWS\system32\node_modules\node-gyp\lib\util.js:54:7
gyp ERR! stack     at C:\WINDOWS\system32\node_modules\node-gyp\lib\util.js:33:16
gyp ERR! stack     at ChildProcess.exithandler (node:child_process:406:5)
gyp ERR! stack     at ChildProcess.emit (node:events:527:28)
gyp ERR! stack     at maybeClose (node:internal/child_process:1092:16)
gyp ERR! System Windows_NT 10.0.22000
gyp ERR! command "D:\\Program Files\\nodejs\\node.exe" "C:\\WINDOWS\\system32\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd C:\WINDOWS\system32\node_modules\node-sass
gyp ERR! node -v v16.16.0
gyp ERR! node-gyp -v v8.4.1
gyp ERR! not ok
Build failed with error code: 1
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

解决方法: 更新 node-gyp 的 npm 捆绑版本

参考: https://github.com/nodejs/node-gyp/blob/main/docs/Updating-npm-bundled-node-gyp.md

  1. cd到node.exe包含的目录,例如:
$ cd "C:\Program Files\nodejs"
  1. 如果您的 npm 版本是_7 或 8_,请执行以下操作:
$ cd node_modules\npm\node_modules\@npmcli\run-script

否则,如果您的 npm 版本_小于 7_,请执行以下操作:

$ cd node_modules\npm\node_modules\npm-lifecycle
  1. 最后通过下面的指令更新node-gyp
$ npm install node-gyp@latest

bug原因:

这个看那个参考文档吧。。。虽说 8.4版本已经支持了vs2022, 可我的版本已经是8.4.1,了,他还是找不到vs,不管了,反正问题也完美解决了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值