Node: Running global npm scripts in node 12.9.0: This command not found error.

Created on 23 Aug 2019  路  20Comments  路  Source: nodejs/node

  • Version: 12.9.0
  • Platform: 64-bit Windows (Windows 10)
  • Subsystem: all global npm scripts (excl. npm and npx)


After upgrading to the latest node release, with the exception of npm and npx, all of the global npm scripts no longer run. For example:
$ tsc --version
produces:
C:\Users\{username}\AppData\Roaming\npm/node_modules/node/bin/node: line 1: This: command not found

Please note that C:\Program Files\nodejs and C:\Users\{username}\AppData\Roaming\npm have already been added to the environment path. I attempted to run the rest of the scripts and they all (with the exception of npm and npx) yielded the same result.

However, the scripts were successful when I ran them directly as in either:
$ C:/Users/{username}/AppData/Roaming/npm/tsc.cmd --version
or
$ C:/Users/{username}/AppData/Roaming/npm/node_modules/typescript/bin/tsc --version

Thank you for investigating as soon as possible. It is a total development blocker for us at the moment.

install

Most helpful comment

I deleted my C:/Users/{username}/AppData/Roaming/npm and C:/Users/{username}/AppData/Roaming/npm-cache and reinstalled global npm modules, and the problem ceased.

It would be much better though if these steps could be avoided after upgrading/downgrading node. If not, then at least, make it explicit in the docs that this step may be necessary when upgrading/downgrading existing node installations.

All 20 comments

I deleted my C:/Users/{username}/AppData/Roaming/npm and C:/Users/{username}/AppData/Roaming/npm-cache and reinstalled global npm modules, and the problem ceased.

It would be much better though if these steps could be avoided after upgrading/downgrading node. If not, then at least, make it explicit in the docs that this step may be necessary when upgrading/downgrading existing node installations.

I think we've observed this kind of thing due to installers not overwriting everything before, but I think that was on macOS.

Hmmm... interesting. To be honest I'm not entirely sure what we would do on the node.js side to address this. @isaacs ... any ideas?

I can't reproduce. The modules stay installed under AppData and work well after a Node upgrade.

@steveswork what shell are you using? Can you paste here the contents of C:/Users/{username}/AppData/Roaming/npm/tsc.cmd and C:/Users/{username}/AppData/Roaming/npm/tsc when that error happens?

@joaocgreis I can no longer obtain it. I discarded it when I discarded the old AppData/Roaming/npm directory and did not reinstall it. One of scripts I reinstalled is bit. That one is using bourne shell.

I have the same issue.
C:\Users\{username}\AppData\Roaming\npm/node_modules/node/bin/node: line 1: This: command not found

Using BASH on Windows 10:

$ node -v
v12.9.1

$ npm -v
6.11.2

$ echo $NODE_PATH
C:\Program Files\nodejs\node.exe

$ which node
/c/nodejs/node

$ where node
C:\nodejs\node.exe
C:\Users\{username}\AppData\Roaming\npm\node
C:\Users\{username}\AppData\Roaming\npm\node.cmd

$ which tsc
/c/Users/{username}/AppData/Roaming/npm/tsc

$ where tsc
C:\Users\{username}\AppData\Roaming\npm\tsc
C:\Users\{username}\AppData\Roaming\npm\tsc.cmd

$ tsc -V
C:\Users\{username}\AppData\Roaming\npm/node_modules/node/bin/node: line 1: This: command not found

$ npm -g list --depth 0
C:\Users\{username}\AppData\Roaming\npm
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]

@steveswork, I have had the same issue for almost a month. Your recommendation resolved the issue for me. Thanks a million !

I deleted my C:/Users/{username}/AppData/Roaming/npm and C:/Users/{username}/AppData/Roaming/npm-cache and reinstalled global npm modules, and the problem ceased.

It would be much better though if these steps could be avoided after upgrading/downgrading node. If not, then at least, make it explicit in the docs that this step may be necessary when upgrading/downgrading existing node installations.

works like a charm. hugee thanks!!

facing same problem now had to delete the folders
why this hasnt been solved?

I deleted my C:/Users/{username}/AppData/Roaming/npm and C:/Users/{username}/AppData/Roaming/npm-cache and reinstalled global npm modules, and the problem ceased.

It would be much better though if these steps could be avoided after upgrading/downgrading node. If not, then at least, make it explicit in the docs that this step may be necessary when upgrading/downgrading existing node installations.

Worked for me too, thanks!

I deleted my C:/Users/{username}/AppData/Roaming/npm and C:/Users/{username}/AppData/Roaming/npm-cache and reinstalled global npm modules, and the problem ceased.

It would be much better though if these steps could be avoided after upgrading/downgrading node. If not, then at least, make it explicit in the docs that this step may be necessary when upgrading/downgrading existing node installations.

Work for me in WSL thanks a lot

I deleted my C:/Users/{username}/AppData/Roaming/npm and C:/Users/{username}/AppData/Roaming/npm-cache and reinstalled global npm modules, and the problem ceased.

It would be much better though if these steps could be avoided after upgrading/downgrading node. If not, then at least, make it explicit in the docs that this step may be necessary when upgrading/downgrading existing node installations.

I had the same problem and solved it using @steveswork 's solution.

Before applying his solution, this was noted:
I am also using bash (MINGW64) primarily on Windows10.

From Bash, I had the error below, when running "serverless ..." which was installed globally, but not when using command prompt.
C:Users{username}AppDataRoamingnpm/node_modules/node/bin/node: line 1: This: command not found

Before installing, I had these node related global versions installed.

npm -g list --depth 0
C:Users{username}AppDataRoamingnpm
+-- [email protected]
+-- [email protected]
`-- [email protected]

Strangely though, checking the node version before applying the solution, I saw this:
node --version
v12.16.3

and after updating to the latest Node LTS:
node --version
v12.18.2

Yes, npm -g lists 14.2.

After applying Steve's solution, both version checks match and the problem is solved.

Hopefully this helps isolate the cause.

@steveswork solutions works for me.

I have been having using using nodemon for a while, but this works .

Thanks

  • Version: 12.18.3
  • Platform: 64-bit Windows (Windows 10)

Ran into exactly the same issue after updating Node.js from v10.16.0 to v12.18.3 on Windows 10 (64-bit). As @steveswork's solution said, I deleted my C:/Users/{username}/AppData/Roaming/npm and C:/Users/{username}/AppData/Roaming/npm-cache and reinstalled global packages but got no luck.

I did some tests to figure out what is actually been done when using package instructions that invoke node (e.g., git cz for my case). It turns out that the shell script node in C:\Program Files\nodejs (my environment path for Node.js) works. And it eventually runs something like:

"$basedir/node_modules/node/bin/node"   "$@"

In C:\Program Files\nodejs\node_modules\node\bin, the file node has content like:

This file intentionally left blank

I don't know if there's any magic here to keep packages working charmingly (If there is, please let me know :-) ). But I guess it may be the reason why invoking node fails. So I just change the name of the file from node to something like node_backup in C:\Program Files\nodejs\node_modules\node\bin to use node.exe intentionally. Then things are working fine now.

PS: The solution mentions here is kind of tricky and I can't tell if it will cause any other unexpected problems. I suggest using it as a temporary work-around.

* Version: 12.18.3

* Platform: 64-bit Windows (Windows 10)

Ran into exactly the same issue after updating Node.js from v10.16.0 to v12.18.3 on Windows 10 (64-bit). As @steveswork's solution said, I deleted my C:/Users/{username}/AppData/Roaming/npm and C:/Users/{username}/AppData/Roaming/npm-cache and reinstalled global packages but got no luck.

I did some tests to figure out what is actually been done when using package instructions that invoke node (e.g., git cz for my case). It turns out that the shell script node in C:\Program Files\nodejs (my environment path for Node.js) works. And it eventually runs something like:

"$basedir/node_modules/node/bin/node"   "$@"

In C:\Program Files\nodejs\node_modules\node\bin, the file node has content like:

This file intentionally left blank

I don't know if there's any magic here to keep packages working charmingly (If there is, please let me know :-) ). But I guess it may be the reason why invoking node fails. So I just change the name of the file from node to something like node_backup in C:\Program Files\nodejs\node_modules\node\bin to use node.exe intentionally. Then things are working fine now.

PS: The solution mentions here is kind of tricky and I can't tell if it will cause any other unexpected problems. I suggest using it as a temporary work-around.

I did this and it worked like a charm! Thank you!!

Thank steveswork, been looking for solution for a couple of hours now.

Version: 14.15.0
OS: Windows 10 pro

Exact issue for me as well. @KuangJie7 solution did not work for me: I have no 'node' file in C:\Program Files\nodejs\node_modules\bin, and not even a 'bin' directory. It is '.bin'.

@steveswork solution worked for me. Drag to have to delete and re-install but there ya have it.

I deleted my C:/Users/{username}/AppData/Roaming/npm and C:/Users/{username}/AppData/Roaming/npm-cache and reinstalled global npm modules, and the problem ceased.

It would be much better though if these steps could be avoided after upgrading/downgrading node. If not, then at least, make it explicit in the docs that this step may be necessary when upgrading/downgrading existing node installations.

This worked for me. Thanks

Another simple way works for me锛宒eleteC:/Users/{username}/AppData/Roaming/npm/node_modules/node

just download the installer from the official site and run it again. worked for me

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sandeepks1 picture sandeepks1  路  3Comments

Icemic picture Icemic  路  3Comments

filipesilvaa picture filipesilvaa  路  3Comments

dfahlander picture dfahlander  路  3Comments

danialkhansari picture danialkhansari  路  3Comments