当前位置: 首页 > news >正文

卸载了Visual Studio后,在vscode中执行npm i或npm i --force时报错,该怎么解决?

卸载了Visual Studio后,在vscode中执行npm i或npm i --force时报错,该怎么解决?

  • 报错内容:
  • 原因
  • 解决办法

报错内容:

npm ERR! code 1
npm ERR! path E:\VScode\codeDate\yugan\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: E:\nodejs\node.exe E:\VScode\codeDate\yugan\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 'E:\nodejs\node.exe',
npm ERR! gyp verb cli 'E:\VScode\codeDate\yugan\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@16.18.1 | 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 "E:\python\python.exe"
npm ERR! gyp verb find Python - executing "E:\python\python.exe" to get version
npm ERR! gyp verb find Python - version is "3.7.4"
npm ERR! gyp info find Python using Python version 3.7.4 found at "E:\python\python.exe"
npm ERR! gyp verb get node dir no --target version specified, falling back to host node version: 16.18.1
npm ERR! gyp verb command install [ '16.18.1' ]
npm ERR! gyp verb install input version string "16.18.1"
npm ERR! gyp verb install installing version: 16.18.1
npm ERR! gyp verb install --ensure was passed, so won't reinstall if already installed
npm ERR! gyp verb install version is already installed, need to check "installVersion"
npm ERR! gyp verb got "installVersion" 9
npm ERR! gyp verb needs "installVersion" 9
npm ERR! gyp verb install version is good
npm ERR! gyp verb get node dir target node version installed: 16.18.1
npm ERR! gyp verb build dir attempting to create "build" dir: E:\VScode\codeDate\yugan\node_modules\node-sass\build
npm ERR! gyp verb build dir "build" dir needed to be created? Yes
npm ERR! gyp verb find VS msvs_version not set from command line or npm config
npm ERR! gyp verb find VS VCINSTALLDIR not set, not running in VS Command Prompt
npm ERR! gyp verb find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details
npm ERR! gyp verb find VS looking for Visual Studio 2015
npm ERR! gyp verb find VS - not found
npm ERR! gyp verb find VS not looking for VS2013 as it is only supported up to Node.js 8
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS msvs_version not set from command line or npm config
npm ERR! gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
npm ERR! gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details
npm ERR! gyp ERR! find VS looking for Visual Studio 2015
npm ERR! gyp ERR! find VS - not found
npm ERR! gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS You need to install the latest version of Visual Studio
npm ERR! gyp ERR! find VS including the "Desktop development with C++" workload.
npm ERR! gyp ERR! find VS For more information consult the documentation at:
npm ERR! gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Could not find any Visual Studio installation to use
npm ERR! gyp ERR! stack at VisualStudioFinder.fail (E:\VScode\codeDate\yugan\node_modules\node-gyp\lib\find-visualstudio.js:122:47)npm ERR! gyp ERR! stack at E:\VScode\codeDate\yugan\node_modules\node-gyp\lib\find-visualstudio.js:75:16
npm ERR! gyp ERR! stack at VisualStudioFinder.findVisualStudio2013 (E:\VScode\codeDate\yugan\node_modules\node-gyp\lib\find-visualstudio.js:363:14)
npm ERR! gyp ERR! stack at E:\VScode\codeDate\yugan\node_modules\node-gyp\lib\find-visualstudio.js:71:14
npm ERR! gyp ERR! stack at E:\VScode\codeDate\yugan\node_modules\node-gyp\lib\find-visualstudio.js:384:16
npm ERR! gyp ERR! stack at E:\VScode\codeDate\yugan\node_modules\node-gyp\lib\util.js:54:7
npm ERR! gyp ERR! stack at E:\VScode\codeDate\yugan\node_modules\node-gyp\lib\util.js:33:16
npm ERR! gyp ERR! stack at ChildProcess.exithandler (node:child_process:410:5)
npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:513:28)
npm ERR! gyp ERR! stack at maybeClose (node:internal/child_process:1100:16)
npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:304:5)
npm ERR! gyp ERR! System Windows_NT 10.0.19044
npm ERR! gyp ERR! command "E:\nodejs\node.exe" "E:\VScode\codeDate\yugan\node_modules\node-gyp\bin\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm ERR! gyp ERR! cwd E:\VScode\codeDate\yugan\node_modules\node-sass
npm ERR! gyp ERR! node -v v16.18.1
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! E:\nodejs\node_cache_logs\2023-12-24T06_35_02_993Z-debug-0.log

一开始我看到这个报错写着这样:“npm ERR! gyp verb find Python checking if “python3” can be used”,这样:“npm ERR! gyp ERR! find VS You need to install the latest version of Visual Studio
npm ERR! gyp ERR! find VS including the “Desktop development with C++” workload.”
报错时我觉得很懵逼,因为vscode中的报错和Visual Studioh、Python有什么关系,然后查找了很多资料之后发现:

原因

1.前端项目中有一些工具包或者处理器等的底层语言是用C++等写的,最初有些工具是用Ruby写的,为了提高性能和扩展性,Sass团队开发了一个名为LibSass的C/C++库,用于实现Sass的底层功能。比如SASS、LESS等;
2.如果你卸载了 Visual Studio,而在使用 VSCode 下载依赖时出现错误,是由于一些 Node.js 包需要依赖 Visual Studio 的构建工具链。当这些包尝试编译二进制插件时,缺少 Visual Studio 可能导致构建失败。

解决办法

1.首先执行命令:
需要以管理员身份打开命令框

npm install -g node-gyp

执行命令 npm install -g node-gyp 是为了全局安装 Node.js 模块 node-gyp。node-gyp 是一个用于编译和构建 Node.js C++ 插件的工具。

当你在项目中使用需要编译的 Node.js 模块时(例如 node-sass),这些模块通常需要通过 node-gyp 进行编译以生成适用于你的操作系统和 Node.js 版本的二进制文件。

通过在命令行中执行 npm install -g node-gyp 命令,你将全局安装 node-gyp 工具,使其可在任何项目中使用。这样,当你在项目中安装需要编译的 Node.js 模块时,它们将能够使用全局安装的 node-gyp 工具进行编译。

2.要全局安装 Windows Build Tools:Windows Build Tools 是一个针对 Node.js 的工具包,它提供了构建 Node.js 项目所需的编译工具链。我们通过运行以下命令全局安装 Windows Build Tools。
需要以管理员身份打开命令框

npm install --global windows-build-tools

它会自动下载和安装 Visual Studio Build Tools、Python 和其他构建所需的依赖,这样就解决了
Node.js 包需要依赖 Visual Studio 的构建工具链等问题了

相关文章:

  • log4j学习
  • 鸿蒙开发中的坑(持续更新……)
  • cfa一级考生复习经验分享系列(十一)
  • 低时延,可扩展的 l4s 拥塞控制算法
  • MySQL——内置函数
  • 【SpringCloud笔记】(10)消息总线之Bus
  • 分支限界法求解01背包(优先队列)【java】
  • 2023年第七届强网杯初赛 WP
  • Python期末复习第一章——概述
  • vmware安装中标麒麟高级服务器操作系统 V7.0
  • 动物分类识别教程+分类释义+界面展示
  • 【排序算法】C语言实现选择排序与冒泡排序
  • OpenEuler安装内网穿透工具实现ssh连接openEuler系统
  • pip install multiprocessing报错子进程错误error: metadata-generation-failed
  • IP代理科普| 共享IP还是独享IP?两者的区别与优势
  • C++哈希表的实现
  • Anylogic Pro 8.8.x for Mac / for Linux Crack
  • DOM and XPATH
  • linux中主从复制的架构和读写分离的方式
  • SpaceDesk如何连接平板/PC(生产力副屏)
  • 杭温高铁、沪苏湖高铁明起推出定期票和计次票,不限车次执行优惠折扣
  • “半世纪来对无争议边界最深入袭击”:印巴冲突何以至此又如何收场?
  • 中邮保险斥资8.69亿元举牌东航物流,持股比例达5%
  • 8小时《大师与玛格丽特》:长度可以是特点,但不是价值标准
  • 李云泽:将尽快推出支持小微企业民营企业融资一揽子政策
  • 丁薛祥在学习《习近平经济文选》第一卷专题研讨班上强调,深入学习贯彻习近平经济思想,加强党中央对经济工作的集中统一领导