I have frequently ran into the issue of not being able to use npm or node within vscodes terminal. I have scoured the internet for the answer yet none of them have worked for me. I have done the following which have been suggested by others. All have been done on a windows machine.
Note: when running npm i and/or npm init I do not get the same errors
- uninstall/reinstall node program from machine(windows 10)
- delete any and all traces of node from programs, folders and pathing's
- add environment variable path
- shutdown and restart terminals
- using gitbash terminal as well as the command prompt to access get the command to work
- uninstalling git after the new node has been installed
Example
npm ERR! code 1 npm ERR! path C:\Users\bai1e\letstudy\node_modules\protobufjs npm ERR! command failed npm ERR! command C:\Windows\system32\cmd.exe /d /s /c C:\Users\bai1e\AppData\Local\Temp\postinstall-a42f6975.cmd npm ERR! 'node' is not recognized as an internal or external command, npm ERR! operable program or batch file.
npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\bai1e\AppData\Local\npm-cache_logs\2022-09-15T02_47_40_653Z-debug-0.log
Portion of Log
0 verbose cli C:\Program Files\nodejs\node.exe C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js 1 info using npm@8.15.0 2 info using node@v16.17.0 3 timing npm:load:whichnode Completed in 0ms 4 timing config:load:defaults Completed in 4ms 5 timing config:load:file:C:\Program Files\nodejs\node_modules\npm\npmrc Completed in 2ms 6 timing config:load:builtin Completed in 2ms 7 timing config:load:cli Completed in 1ms 8 timing config:load:env Completed in 1ms 9 timing config:load:file:C:\Users\bai1e\letstudy.npmrc Completed in 0ms 10 timing config:load:project Completed in 2ms 11 timing config:load:file:C:\Users\bai1e.npmrc Completed in 0ms