[npm] node-gpy embedded npm version upgrade (to solve the problem that node-gpy embedded npm version is too low to recognize the 2022 msvs_version version)
This time, run the front-end code of another vue project given to us by the classmate, configure the environment, install nodeJs and node-gpy, run after installation to build the npm install
project, report an error, first report an error error gyp ERR! stack Error: Could not find any Visual Studio installation to use
, Visual Studio is not installed, follow the method of the boss , on the official website Downloaded Visual Studio Build Tools
and installed the C++ tool, the latest version is version 2022, re-executenpm install
question
Still reporting an error unknown version "undefined" found at "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTool
, I searched online and found that it was because the version of npm was too low, and the latest 2022 version of VS Build Tools could not be recognized, but I node-gpy -v
already updating npm update node-gyp -g
or $ npm install node-gyp@latest
not having any effect
reason
After careful observation, I found that the npm version displayed in the error report is not consistent with the npm version I found on the command line. Based on the above ideas, I finally found https://github.com/nodejs/node-gyp/blob/main/ docs/Updating-npm-bundled-node-gyp.md , found that node-gpy will use the embedded npm, and the embedded version is too low, and the simple external upgrade command has no effect.
solve
The solution for windows: (For other solutions, please refer to the link to see the document description)
Execute as an administrator and enter the installation location of nodeJs
$ cd "C:\Program Files\nodejs"
If the external npm is 7 or 8 (this can be checked with npm -v):
cd node_modules\npm\node_modules\@npmcli\run-script
less than 7
cd node_modules\npm\node_modules\npm-lifecycle
Run the update command again under these two folders
$ npm install node-gyp@latest