-
Notifications
You must be signed in to change notification settings - Fork 284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
npm doesn't work in PowerShell, only npm.cmd does #4436
Comments
@anonrig Is this nodejs/node#53538? |
Can you confirm you installed node.js in the powershell environment, and not just cmd prompt (node -v)? Yes I know its weird, but sometimes it just happens. If you have, try running as admin and:
with npm.cmd for the first npm. If that still doesn't work, you will have to go into your PATH environment and manually set 'npm' as a command variable bc if npm.cmd works then you definitely have npm, but for whatever reason the PATH variable never got set or never got set globally, or was removed. |
Thanks for the advice and links, so far manipulating the environment variable has not helped. I will try the advice provided in the links. At the same time, when selecting сmd or git bash, the command npm works in the terminal, the problem is only with the PowerShall |
Thanks for the info! Could you glance over the linked issue and let me know whether they are the same problem? Thanks! |
Hey @OksanaML78, did you get a chance to test the comment above? If so, how did it go? (What happens with Also, did @hzhang20902 |
Everything works fine for me on the command line, why it doesn’t work with PowerShall I haven’t found a solution. I just started working through the command line |
after npm install -g npm nothing changed in PowerShall. I used this command before but there are no changes |
Hmm, strange, what about reinstalling Node.js from the official website? |
I reinstalled not only the Node.js but also the PowerShall several times from the official website - no changes.....I wrote about it |
Oh, sorry, I didn't refresh myself on the issue contents, my bad. @nodejs/npm PTAL |
I checked all the folders indicated in the links, I installed the installation from the same account from which I am executing the commands - but it works in PowerShall only this way npm.cmd , again with the command line and gitBash there are no problems - command npm work |
it would help to put in the error msg, or some other context, bc we're only guessing based off little bits of info you're giving us here and there. did you explicitly set the PATH env variable to be executed when you run the 'npm' command within powershell, to be "C:\Program Files\nodejs", or a prefix file that describes similar actions? As in, you can confirm that you yourself did this, or have found the prefix file specifically for Powershell that states NODE EXE and NPM PREFIX JS, or NPM CLI JS, or some other combination of those variable names are set to some kind of nodejs directory, npm prefix file, something? you should be able to open the files in the nodejs directory to check, if you have vs code, use Because if npm.cmd works, then it's just something not set correctly with your Path to the executable. The nodejs directory in Program Files includes npm command prefixes for all 3 of the shells you mentioned, cmd prompt, bash, and powershell, in 3 separate files, as well as versions for the npx command. which means whenever you installl node, it automatically comes with scripts that sets it for those 3 shell environments. it's all or nothing. but again, not much context to go off of. however, you should look into if these are set correctly first before anything else, bc that seems to be the root of your problem. |
Yes of course, this is what I have and the errors, I can show -> cmd: C:\Windows\System32>npm audit in this log file 2024-07-09T08_45_08_197Z-debug-0.log -> 0 verbose cli C:\Program Files\nodejs\node.exe C:\Users\oksa\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js environment variable in cmd-> C:\Windows\System32>echo %PATH% |
in PowerShall: Windows PowerShell Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows PS C:\Windows\system32> npm -v |
for the last command, you can use |
PowerShall -> PS C:\Windows\system32> $env:Path -split ";" |
ok so this clears some things up. please in the future, when you have an error like this, explain the error in context, because no one can tell that the "error" you are receiving in powershell is not an error but just no output, because that means the process actually did run, and ran successfully, it just did not give you output in the powershell environment. remember that errors will ALWAYS be pointed out, and will show line by line, like that npm audit error log, so NO OUTPUT does NOT equal ERROR. for reference, the shell is a REPL (read-evaluate-print loop) so it reads your input, evaluates which process to execute, and prints the result or output, in a loop. Like the error log is a line by line of this loop. The PRINT part means it will always OUTPUT something to somewhere. Here, your issue is the SOMETHING is not going to the SOMEWHERE that you want it to.There is indeed a SOMETHING, we know this because an error did not get raised (and you verified the nodejs installation and path env vars, etc). We just don't know the SOMEWHERE it got sent to. This is probably caused by an AutoRun configuration being run either in your user account or global system. To fix it, try these first:
I would suggest use the latest version of Node.js and NPM, which should be 22 something and 10.8 something. They should come that way if you choose the latest version in the link above, because If none of this works, then there is something within the npm.cmd and/or npm.ps1 files within the Program Files/nodejs/ directory that has been corrupted, or is being set incorrectly, for reasons beyond the scope of either node.js or any installations, and exceeds the capabilities of most users, like you and me, to be able to fix. |
Thanks for the detailed answer, @hzhang20902! @OksanaML78 - if this resolves your issue, feel free to close this issue. |
Thank you, I checked the registry again, because... I also checked earlier and I don’t have AutoRun in both folders, but nevertheless I once again deleted everything related to nodejs and installed the latest versions, but still the problem remained. |
If the problem persists, no need to close the issue |
Thank you, but I can’t bother you anymore because... I already use the command line with which I have no problems, the problem with PowerShell is not so critical for me now |
It's no bother! If you leave this issue open, more users will see it, and they may have solutions. |
Dang, thats really strange. Idk anymore, my best guess is audit your registry for any delayed expansion variables, but thats just based off the description of what they are, im not familiar with them. Weird that # running the cmd prompt command in PS outputs to PS but not its alias. You could try auditing the cmd extension as well, but at this point probably more trouble than its worth 😅 |
Just run this command in powershell as admin What it does is it allows PowerShell scripts that are created on your local machine to run without needing a digital signature. |
I had the same issue...
I ran this command in powershell as admin:
|
this work for me
|
Node.js Version
v20.15.0
NPM Version
v10.8.0
Operating System
Windows 11 Pro
Subsystem
console, Other
Description
In PowerShell terminal, the npm command doesn't work; only npm.cmd works. However, in Command Prompt, the npm command works. To troubleshoot, I have reinstalled Node.js, PowerShell, checked environment variables, confirmed the path is set correctly, and npm.cmd exists in the nodejs folder.
Minimal Reproduction
No response
Output
No response
Before You Submit
The text was updated successfully, but these errors were encountered: