ApliNi / blog

GNU General Public License v3.0
2 stars 0 forks source link

windows, 速通 npm install 报错 #29

Open ApliNi opened 3 weeks ago

ApliNi commented 3 weeks ago

npm install

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

没有安装构建工具, 一部分依赖会需要这些工具才能正常安装, 如 better-sqlite3.

解决方法:

  1. 找到 nodejs 安装位置, 在 Windows 上是 C:\Program Files\nodejs
  2. 运行 install_tools.bat, 根据提示安装, 可能会遇到其他错误
  3. 等待安装完成, 检查是否出错, 重新运行安装命令

npm ERR! prebuild-install warn install unable to verify the first certificate
npm ERR! gyp info it worked if it ends with ok
...
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1

有时可以通过更新 npm 解决.

解决方法:

  1. 在控制台底部找到类似 npm notice Run npm install -g npm@10.8.3 to update! 的信息
  2. 运行其中这样的部分: npm install -g npm@10.8.3 完成 npm 更新
  3. 重新运行安装命令

install_tools

Chocolatey upgraded 0/2 packages. 
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

choco 是 windows 上的包管理器, 用来安装和管理软件. 如果一些软件通过错误的方式被卸载或者因为安装失败等原因损坏可能需要手动清理一些文件.

解决方法: (如果以前有运行过 install_tools)

  1. 找到目录 C:\ProgramData\chocolatey\lib
  2. 备份并删除 python, python3, python312, vcredist140, vcredist2015, visualstudio2019buildtools, visualstudio2019-workload-vctools, visualstudio-installer 文件夹
  3. 重新运行 install_tools.bat

解决方法: (如果没用过 choco 安装软件)

  1. 备份并删除 C:\ProgramData\chocolatey 目录
  2. 重新运行 install_tools.bat