npm install -g node-gyp
npm install node-pre-gyp -g
管理员身份运行Power Shell
npm install --global --production windows-build-tools
中途卡住可按提示位置找到exe手动安装VisualStudio
或在此下载安装:https://visualstudio.microsoft.com/zh-hans/visual-cpp-build-tools/
勾选安装“使用C++的桌面开发”
如果以上安装的都是最新版,并安装了python3.6+版本,重启下电脑即可npm install项目了(一定要重启!)
以下是过往老版本时遇到的各类问题:
配置Python版本
npm config set python python2.7
(使用 python -V 查看版本,配置相同的版本)
最终会有额外大文件node_modules\sqlite3\build-tmp-napi-v6,52MB删掉
----2024-2-28
新版npm在config set python时报错,需要降级:npm i -g npm@8
----2024-12-26
新版的gyp需要python3.6+版本,安装新版后配置环境变量:
setx PATH "%PATH%;C:\Path\To\Your\Python3"
Comments | NOTHING