How to run npm command correctly in WSL

I got this error when I run the npm run start command in wsl

/mnt/f/nodejs/npm: line 3: $'r': command not found
/mnt/f/nodejs/npm: line 5: $'r': command not found
/mnt/f/nodejs/npm: line 6: syntax error near unexpected token `$'inr''
'mnt/f/nodejs/npm: line 6: `case `uname` in


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

It appears that you shared files (including node_modules) from a Windows install directly into a WSL Linux distro (the /mnt/f is highly suspicious). You likely have all your source and did your npm install in Windows, but then just tried to run node in WSL. Unfortunately that’s a platform mismatch and (as Cody G mentioned in a comment), you need to npm install through WSL. This is further evidenced by the fact that the error messages indicate that it’s choking on r, which is the first character of a Windows platform CRLF line ending (rn). But your Linux distro will want LF endings (n).

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x