Skip to content
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

Issue running npm command #1512

Closed
RichiCoder1 opened this issue Dec 16, 2016 · 91 comments
Closed

Issue running npm command #1512

RichiCoder1 opened this issue Dec 16, 2016 · 91 comments

Comments

@RichiCoder1
Copy link

@RichiCoder1 RichiCoder1 commented Dec 16, 2016

When running "npm" from bash, I get the following error:

richard@RICH-HOME:/mnt/c/Users/Richard$ npm
: not foundram Files/nodejs/npm: 3: /mnt/c/Program Files/nodejs/npm:
: not foundram Files/nodejs/npm: 5: /mnt/c/Program Files/nodejs/npm:
/mnt/c/Program Files/nodejs/npm: 6: /mnt/c/Program Files/nodejs/npm: Syntax error: word unexpected (expecting "in")
  • Your Windows build number

    • Windows 10 Pro Insider Preview / Build 14965
  • Steps / All commands required to reproduce the error from a brand new installation

  • Strace of the failing command

richard@RICH-HOME:/mnt/c/Users/Richard$ strace npm                                                                                                                              
execve("/mnt/c/Program Files/nodejs/npm", ["npm"], [/* 15 vars */]) = 0                                                                                                         
brk(0)                                  = 0x7fffd3e7a000                                                                                                                        
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)                                                                                                 
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7ff28e0b0000                                                                                       
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)                                                                                                 
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3                                                                                                                                
fstat(3, {st_mode=S_IFREG|0644, st_size=18732, ...}) = 0                                                                                                                        
mmap(NULL, 18732, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7ff28e0b2000                                                                                                                
close(3)                                = 0                                                                                                                                     
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)                                                                                                 
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3                                                                                                                 
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P \2\0\0\0\0\0"..., 832) = 832                                                                                           
fstat(3, {st_mode=S_IFREG|0755, st_size=1840928, ...}) = 0                                                                                                                      
mmap(NULL, 3949248, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7ff28da30000                                                                                      
mprotect(0x7ff28dbea000, 2097152, PROT_NONE) = 0                                                                                                                                
mmap(0x7ff28ddea000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1ba000) = 0x7ff28ddea000                                                            
mmap(0x7ff28ddf0000, 17088, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7ff28ddf0000                                                                  
close(3)                                = 0                                                                                                                                     
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7ff28e0a0000                                                                                       
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7ff28e090000                                                                                       
arch_prctl(ARCH_SET_FS, 0x7ff28e090740) = 0                                                                                                                                     
mprotect(0x7ff28ddea000, 16384, PROT_READ) = 0                                                                                                                                  
mprotect(0x7ff28e41b000, 8192, PROT_READ) = 0                                                                                                                                   
mprotect(0x7ff28e022000, 4096, PROT_READ) = 0                                                                                                                                   
munmap(0x7ff28e0b2000, 18732)           = 0                                                                                                                                     
getpid()                                = 86                                                                                                                                    
rt_sigaction(SIGCHLD, {0x7ff28e212460, ~[RTMIN RT_1], SA_RESTORER, 0x7ff28da66cb0}, NULL, 8) = 0                                                                                
geteuid()                               = 1000                                                                                                                                  
brk(0)                                  = 0x7fffd3e7a000                                                                                                                        
brk(0x7fffd3e9b000)                     = 0x7fffd3e9b000                                                                                                                        
getppid()                               = 83                                                                                                                                    
stat("/mnt/c/Users/Richard", {st_mode=S_IFDIR|0777, st_size=0, ...}) = 0                                                                                                        
stat(".", {st_mode=S_IFDIR|0777, st_size=0, ...}) = 0                                                                                                                           
open("/mnt/c/Program Files/nodejs/npm", O_RDONLY) = 3                                                                                                                           
fcntl(3, F_DUPFD, 10)                   = 10                                                                                                                                    
close(3)                                = 0                                                                                                                                     
fcntl(10, F_SETFD, FD_CLOEXEC)          = 0                                                                                                                                     
rt_sigaction(SIGINT, NULL, {SIG_DFL, [], SA_RESTORER, 0x7f5c3c426cb0}, 8) = 0                                                                                                   
rt_sigaction(SIGINT, {0x7ff28e212460, ~[RTMIN RT_1], SA_RESTORER, 0x7ff28da66cb0}, NULL, 8) = 0                                                                                 
rt_sigaction(SIGQUIT, NULL, {SIG_DFL, [], SA_RESTORER, 0x7f5c3c426cb0}, 8) = 0                                                                                                  
rt_sigaction(SIGQUIT, {SIG_DFL, ~[RTMIN RT_1], SA_RESTORER, 0x7ff28da66cb0}, NULL, 8) = 0                                                                                       
rt_sigaction(SIGTERM, NULL, {SIG_DFL, [], SA_RESTORER, 0x7f5c3c426cb0}, 8) = 0                                                                                                  
rt_sigaction(SIGTERM, {SIG_DFL, ~[RTMIN RT_1], SA_RESTORER, 0x7ff28da66cb0}, NULL, 8) = 0                                                                                       
read(10, "#!/bin/sh\r\n(set -o igncr) 2>/dev"..., 8192) = 867                                                                                                                   
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7ff28e090a10) = 87                                                                   
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 2}], 0, NULL) = 87                                                                                                                
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=87, si_status=2, si_utime=0, si_stime=0} ---                                                                          
rt_sigreturn()                          = 87                                                                                                                                    
stat("/usr/local/sbin/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                              
stat("/usr/local/bin/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                               
stat("/usr/sbin/\r", 0x7fffdbcd7690)    = -1 ENOENT (No such file or directory)                                                                                                 
stat("/usr/bin/\r", 0x7fffdbcd7690)     = -1 ENOENT (No such file or directory)                                                                                                 
stat("/sbin/\r", 0x7fffdbcd7690)        = -1 ENOENT (No such file or directory)                                                                                                 
stat("/bin/\r", 0x7fffdbcd7690)         = -1 ENOENT (No such file or directory)                                                                                                 
stat("/usr/games/\r", 0x7fffdbcd7690)   = -1 ENOENT (No such file or directory)                                                                                                 
stat("/usr/local/games/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                             
stat("/mnt/c/Program Files/ConEmu/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                  
stat("/mnt/c/Program Files/ConEmu/ConEmu/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                           
stat("/mnt/c/ProgramData/Oracle/Java/javapath/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                      
stat("/mnt/c/Program Files (x86)/Razer Chroma SDK/bin/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                              
stat("/mnt/c/Program Files/Razer Chroma SDK/bin/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                    
stat("/mnt/c/Windows/System32/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                      
stat("/mnt/c/Windows/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                               
stat("/mnt/c/Windows/System32/wbem/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                 
stat("/mnt/c/Windows/System32/WindowsPowerShell/v1.0/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                               
stat("/mnt/c/ProgramData/chocolatey/bin/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                            
stat("/mnt/c/Program Files/Java/jdk1.8.0_112/bin/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                   
stat("/mnt/c/Program Files (x86)/Skype/Phone/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                       
stat("/mnt/c/Program Files/Microsoft SQL Server/120/Tools/Binn/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                     
stat("/mnt/c/Program Files/Microsoft SQL Server/130/Tools/Binn/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                     
stat("/mnt/c/Program Files (x86)/Microsoft Emulator Manager/1.0/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                    
stat("/mnt/c/Program Files (x86)/Windows Kits/10/Windows Performance Toolkit/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                       
stat("/mnt/c/Program Files/Microsoft/Web Platform Installer/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                        
stat("/mnt/c/Program Files/Microsoft DNX/Dnvm/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                      
stat("/mnt/c/Program Files/Microsoft SQL Server/Client SDK/ODBC/130/Tools/Binn/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                     
stat("/mnt/c/Program Files (x86)/Microsoft SQL Server/130/Tools/Binn/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                               
stat("/mnt/c/Program Files/Microsoft SQL Server/130/DTS/Binn/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                       
stat("/mnt/c/Program Files/TortoiseGit/bin/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                         
stat("/mnt/c/Program Files/Seq/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                     
stat("/mnt/c/Program Files/Git/cmd/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                 
stat("/mnt/c/Program Files/nodejs/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                  
stat("/mnt/c/Program Files/dotnet/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                  
stat("/mnt/c/Windows/System32/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                      
stat("/mnt/c/Windows/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                               
stat("/mnt/c/Windows/System32/wbem/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                 
stat("/mnt/c/Windows/System32/WindowsPowerShell/v1.0/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                               
stat("/mnt/c/Program Files (x86)/Yarn/bin/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                          
stat("/mnt/c/Users/Richard/.dnx/runtimes/dnx-clr-win-x86.1.0.0-rc1-update2/bin/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                     
stat("/mnt/c/Users/Richard/AppData/Local/Microsoft/WindowsApps/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                     
stat("/mnt/c/Program Files (x86)/Microsoft VS Code/bin/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                             
stat("/mnt/c/Users/Richard/AppData/Local/.meteor/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                   
stat("/mnt/c/tools/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                                 
stat("/mnt/c/Users/Richard/AppData/Roaming/npm/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                     
stat("/mnt/c/Users/Richard/AppData/Local/Microsoft/WindowsApp/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                      
write(2, "/mnt/c/Program Files/nodejs/npm:"..., 69/mnt/c/Program Files/nodejs/npm: 3: /mnt/c/Program Files/nodejs/npm: ) = 69                                                   
: not found)           = 122                                                                                                                                                    
write(2, "\n", 1                                                                                                                                                                
)                       = 1                                                                                                                                                     
pipe([3, 4])                            = 0                                                                                                                                     
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7ff28e090a10) = 88                                                                   
close(4)                                = 0                                                                                                                                     
read(3, "/mnt/c/Program Files/nodejs\n", 128) = 28                                                                                                                              
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=88, si_status=0, si_utime=0, si_stime=0} ---                                                                          
rt_sigreturn()                          = 28                                                                                                                                    
read(3, "", 128)                        = 0                                                                                                                                     
close(3)                                = 0                                                                                                                                     
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 88                                                                                                                
stat("/usr/local/sbin/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                              
stat("/usr/local/bin/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                               
stat("/usr/sbin/\r", 0x7fffdbcd7690)    = -1 ENOENT (No such file or directory)                                                                                                 
stat("/usr/bin/\r", 0x7fffdbcd7690)     = -1 ENOENT (No such file or directory)                                                                                                 
stat("/sbin/\r", 0x7fffdbcd7690)        = -1 ENOENT (No such file or directory)                                                                                                 
stat("/bin/\r", 0x7fffdbcd7690)         = -1 ENOENT (No such file or directory)                                                                                                 
stat("/usr/games/\r", 0x7fffdbcd7690)   = -1 ENOENT (No such file or directory)                                                                                                 
stat("/usr/local/games/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                             
stat("/mnt/c/Program Files/ConEmu/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                  
stat("/mnt/c/Program Files/ConEmu/ConEmu/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                           
stat("/mnt/c/ProgramData/Oracle/Java/javapath/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                      
stat("/mnt/c/Program Files (x86)/Razer Chroma SDK/bin/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                              
stat("/mnt/c/Program Files/Razer Chroma SDK/bin/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                    
stat("/mnt/c/Windows/System32/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                      
stat("/mnt/c/Windows/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                               
stat("/mnt/c/Windows/System32/wbem/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                 
stat("/mnt/c/Windows/System32/WindowsPowerShell/v1.0/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                               
stat("/mnt/c/ProgramData/chocolatey/bin/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                            
stat("/mnt/c/Program Files/Java/jdk1.8.0_112/bin/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                   
stat("/mnt/c/Program Files (x86)/Skype/Phone/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                       
stat("/mnt/c/Program Files/Microsoft SQL Server/120/Tools/Binn/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                     
stat("/mnt/c/Program Files/Microsoft SQL Server/130/Tools/Binn/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                     
stat("/mnt/c/Program Files (x86)/Microsoft Emulator Manager/1.0/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                    
stat("/mnt/c/Program Files (x86)/Windows Kits/10/Windows Performance Toolkit/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                       
stat("/mnt/c/Program Files/Microsoft/Web Platform Installer/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                        
stat("/mnt/c/Program Files/Microsoft DNX/Dnvm/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                      
stat("/mnt/c/Program Files/Microsoft SQL Server/Client SDK/ODBC/130/Tools/Binn/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                     
stat("/mnt/c/Program Files (x86)/Microsoft SQL Server/130/Tools/Binn/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                               
stat("/mnt/c/Program Files/Microsoft SQL Server/130/DTS/Binn/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                       
stat("/mnt/c/Program Files/TortoiseGit/bin/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                         
stat("/mnt/c/Program Files/Seq/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                     
stat("/mnt/c/Program Files/Git/cmd/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                 
stat("/mnt/c/Program Files/nodejs/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                  
stat("/mnt/c/Program Files/dotnet/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                  
stat("/mnt/c/Windows/System32/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                      
stat("/mnt/c/Windows/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                               
stat("/mnt/c/Windows/System32/wbem/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                 
stat("/mnt/c/Windows/System32/WindowsPowerShell/v1.0/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                               
stat("/mnt/c/Program Files (x86)/Yarn/bin/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                          
stat("/mnt/c/Users/Richard/.dnx/runtimes/dnx-clr-win-x86.1.0.0-rc1-update2/bin/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                     
stat("/mnt/c/Users/Richard/AppData/Local/Microsoft/WindowsApps/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                     
stat("/mnt/c/Program Files (x86)/Microsoft VS Code/bin/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                             
stat("/mnt/c/Users/Richard/AppData/Local/.meteor/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                   
stat("/mnt/c/tools/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                                                 
stat("/mnt/c/Users/Richard/AppData/Roaming/npm/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                                     
stat("/mnt/c/Users/Richard/AppData/Local/Microsoft/WindowsApp/\r", 0x7fffdbcd7690) = -1 ENOENT (No such file or directory)                                                      
write(2, "/mnt/c/Program Files/nodejs/npm:"..., 69/mnt/c/Program Files/nodejs/npm: 5: /mnt/c/Program Files/nodejs/npm: ) = 69                                                   
: not found)           = 122                                                                                                                                                    
write(2, "\n", 1                                                                                                                                                                
)                       = 1                                                                                                                                                     
write(2, "/mnt/c/Program Files/nodejs/npm:"..., 69/mnt/c/Program Files/nodejs/npm: 6: /mnt/c/Program Files/nodejs/npm: ) = 69                                                   
write(2, "Syntax error: word unexpected (e"..., 46Syntax error: word unexpected (expecting "in")) = 46                                                                          
write(2, "\n", 1                                                                                                                                                                
)                       = 1                                                                                                                                                     
exit_group(2)                           = ?                                                                                                                                     
+++ exited with 2 +++                                                                                                                                                           
  • Required packages and commands to install
    • NodeJS (windows)
    • npm
@benhillis
Copy link
Member

@benhillis benhillis commented Dec 16, 2016

Interesting, I wonder why all of the paths that are being stat'ed have a '\r' character at the end... I suspect this is coming from some config file that needs to be converted to Unix line endings (probably /mnt/c/Program Files/nodejs/npm). How did you generate this file?

Could you try running dos2unix /mnt/c/Program Files/nodejs/npm and rerunning the command?

@RichiCoder1
Copy link
Author

@RichiCoder1 RichiCoder1 commented Dec 16, 2016

Standard NPM install as far as I'm aware.

Got this fun error back:

richard@RICH-HOME:/mnt/c/Users/Richard$ sudo dos2unix /mnt/c/Program\ Files/nodejs/npm
[sudo] password for richard:
dos2unix: Failed to open temporary output file: Permission denied
dos2unix: converting file /mnt/c/Program Files/nodejs/npm to Unix format ...
dos2unix: problems converting file /mnt/c/Program Files/nodejs/npm
@benhillis
Copy link
Member

@benhillis benhillis commented Dec 16, 2016

Maybe run bash.exe elevated? The Program Files directory might be locked down to non admin users.

@RichiCoder1
Copy link
Author

@RichiCoder1 RichiCoder1 commented Dec 16, 2016

Ah, that was it all right. Got this error now:

richard@RICH-HOME:/mnt/c/Users/Richard$ npm
module.js:472
    throw err;
    ^

Error: Cannot find module 'C:\mnt\c\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:420:7)
    at startup (bootstrap_node.js:139:9)
    at bootstrap_node.js:535:3

But I'm thinking that may be a quirk of windows<->linux?

@krzysztofantczak
Copy link

@krzysztofantczak krzysztofantczak commented Dec 27, 2016

Why just not use NPM from ubuntu side? It works perfectly fine. Also, NVM works really well here.

@RichiCoder1
Copy link
Author

@RichiCoder1 RichiCoder1 commented Dec 27, 2016

The honest answer was I was in bash shell by accident when I ran the initial command, just figured I should report it.

@bubthegreat
Copy link

@bubthegreat bubthegreat commented Jan 30, 2017

Just hit this issue as well - haven't found a good fix yet either. If you end up finding one that works - please post here - I will as well.

@kylemh
Copy link

@kylemh kylemh commented Mar 24, 2017

I did the node installer on Windows 10, restarted my computer, and tried running NPM with the same exact trace as @benhillis - I'm using Bash for Ubuntu via developer mode.

This feedback:

: not foundram Files/nodejs/npm: 3: /mnt/c/Program Files/nodejs/npm:
: not foundram Files/nodejs/npm: 5: /mnt/c/Program Files/nodejs/npm:
/mnt/c/Program Files/nodejs/npm: 6: /mnt/c/Program Files/nodejs/npm: Syntax error: word unexpected (expecting "in")

Occurs after any usage of $ npm - regardless of the flag or instruction used in conjunction.

@chrisdhanaraj
Copy link

@chrisdhanaraj chrisdhanaraj commented Apr 2, 2017

Looks like some sort of conflict between Node on Windows and Node installed inside of the subsystem. I installed both (Node on Windows to get Hyper operational) and then node on the subsystem for everything else - I kind of assumed that because the node on the subsystem was the binary being used (if I did a where node) that I wouldn't run into these problems. No dice, get the same error as everyone else

@aseering
Copy link
Contributor

@aseering aseering commented Apr 2, 2017

@chrisdhanaraj -- could you confirm the same for npm? Specifically, if you do which npm at a bash prompt, what is printed out in response?

For what it's worth, I have npm installed in both Windows and WSL, and I don't experience this problem. For me:

$ which npm
/usr/bin/npm
@mrtopf
Copy link

@mrtopf mrtopf commented Apr 2, 2017

So I now simply installed the most recent version of node like on ubuntu:

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

(the newer node version also include npm already)

More details here: https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions

Now this is used inside hyper.js/bash. The windows installation is still there but basically ignored by bash.

@petetnt
Copy link

@petetnt petetnt commented May 11, 2017

I was having this issue when running zsh with oh-my-zsh inside the WSL. but changing the PATH helped.

In my ~/.bashrc

I have this script to automatically go to zsh when launching bash:

if test -t 1; then
exec zsh
fi

I installed node for the Ubuntu side too with the command above:

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

But I was still running into the same error because my which npm pointed to Program Files, while sudo which npm pointed usr/bin/npm. Exporting the correct path was the correct solution, the oh-my-zsh creates a handy configured ~/.zshrc file, which has this on top:

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

Which I changed to the default Ubuntu one export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games and sourced the file with source ~/.zshrc and everything started working just fine.

@BurtHarris
Copy link

@BurtHarris BurtHarris commented May 20, 2017

Unfortunately, the very first thing I tried using wsl bash was npm install, producing the same disappointing result:

burt@SHUTTLE:~$ npm
: not foundram Files/nodejs/npm: 3: /mnt/c/Program Files/nodejs/npm:
: not foundram Files/nodejs/npm: 5: /mnt/c/Program Files/nodejs/npm:
/mnt/c/Program Files/nodejs/npm: 6: /mnt/c/Program Files/nodejs/npm: Syntax error: word unexpected (expecting "in")
burt@SHUTTLE:~$ which npm
/mnt/c/Program Files/nodejs/npm

The error message really sucks. I'm guessing this is probably caused by to the space in Program Files, so I'm guessing this is likely to impact lots of programs installed on from Windows, not just npm. For someone like me who's just dabbling in bash this is a bad experience.

I'm a Windows developer through and through, but IMHO allowing spaces in directory names was one of the bigger mistakes in the Windows NT. Allowing spaces was surpassed only by including spaces in the normal names of system folders. Have I gotten burned by that again?

Is it possible to "fix" this by patching up the UNIX version of the PATH environment variable using quotes or something?

@phucanhapril
Copy link

@phucanhapril phucanhapril commented May 23, 2017

hi y'all, here's how i got my stuff working. i'm on ubuntu for windows 10 (on a windows VM--i don't think the VM part matters though). i was getting the same errors as @RichiCoder1

$ npm -v
: not foundram Files/nodejs/npm: 3: /mnt/c/Program Files/nodejs/npm:
: not foundram Files/nodejs/npm: 5: /mnt/c/Program Files/nodejs/npm:
/mnt/c/Program Files/nodejs/npm: 6: /mnt/c/Program Files/nodejs/npm: Syntax error: word unexpected (expecting "in")

i have node installed for windows (off the nodejs site). i kept it around, and in addition i followed @mrtopf's install instructions

$ curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
$ sudo apt-get install -y nodejs

then i made some changes to my PATH in my ~/.profile

PATH="$HOME/bin:$HOME/.local/bin:/usr/bin:$PATH"

and sourced it source ~/.profile

what i'm doing up there is telling bash where & in what order to look for my commands, separated by : so i'm saying first look in $HOME/bin then $HOME/.local/bin etc.

you should which npm and use the path where your ubuntu npm is. here's mine:

$ which npm
/usr/bin/npm

so i added /usr/bin to my PATH. /usr/bin needs to go BEFORE $PATH. i check that everything's OK now

$ whereis npm
npm: /usr/bin/npm /mnt/c/Program Files/nodejs/npm /mnt/c/Program Files/nodejs/npm.cmd

bash will use /usr/bin/npm before the npm in Program Files
now i can npm install with no problems :-)

@felipemanga
Copy link

@felipemanga felipemanga commented Jun 3, 2017

Hello,

I just had this issue, and I didn't want to have a second npm install.
I fixed it by changing the line endings in the npm script and removing the ".exe" in the following line:
NODE_EXE="$basedir/node"

Next I created a "Program Files/nodejs/node" script:

#!/bin/bash

for var in "$@"
do
  if [ -e "$var" ]
  then
      var=$(echo "$var" | sed -e 's,^/mnt/\([a-z]\)/,\1:/,' | sed -e 's,/,\\,g')
  fi

  Args=("${Args[@]}" "$var")
done

node.exe "${Args[@]}"

That translates "node /mnt/c/Users/..../file.js" into "node.exe c:\users....\file.js"
To test, I ran:
npm install -g gulp (installed gulp globally, in AppData/Roaming/npm, as expected)
npm install gulp (installed gulp in project)
gulp (executed the global gulp shell script)

@hellobrian
Copy link

@hellobrian hellobrian commented Jun 3, 2017

@phucanhapril your $PATH changes worked like a charm! 💯 Thank you! 👍

@yduman
Copy link

@yduman yduman commented Jun 15, 2017

@phucanhapril you saved me a lot of time thanks! 👍

@Georg-W
Copy link

@Georg-W Georg-W commented Aug 5, 2017

Just restarting the command promp after the node installation on the bash resolved this error for me.

@ranneyd
Copy link

@ranneyd ranneyd commented Aug 16, 2017

@Georg-W now I feel stupid. Good call!

@jepperaskdk
Copy link

@jepperaskdk jepperaskdk commented Sep 2, 2017

Running with sudo worked for me, when attempting to install less:

*removed*:/mnt/c/Users/Jeppe$ npm install -g less
: not foundram Files/nodejs/npm: 3: /mnt/c/Program Files/nodejs/npm:
: not foundram Files/nodejs/npm: 5: /mnt/c/Program Files/nodejs/npm:
/mnt/c/Program Files/nodejs/npm: 6: /mnt/c/Program Files/nodejs/npm: Syntax error: word unexpected (expecting "in")
*removed*:/mnt/c/Users/Jeppe$ sudo !!
sudo npm install -g less
sudo: unable to resolve host DESKTOP-K3QCK34
npm http GET https://registry.npmjs.org/less
... rest of installation, which succeeded.
@murpyslaw
Copy link

@murpyslaw murpyslaw commented Sep 21, 2017

I've found out what causes:

: not foundram Files/nodejs/npm: 3: /mnt/c/Program Files/nodejs/npm:
: not foundram Files/nodejs/npm: 5: /mnt/c/Program Files/nodejs/npm:
/mnt/c/Program Files/nodejs/npm: 6: /mnt/c/Program Files/nodejs/npm: Syntax error: word unexpected (expecting "in")

If you open

vim -b `which npm` 

you will see the probably somebody upstream messed up and forgot to turn on git config core.autoctrlf true, thus causing a BUNCH of ^M to be appended to each line.
The problem is that, even when these are removed, they are everywhere in the nodejs repo.

I'm not sure if there's any way besides using the Windows Installer to install node for now.

Edit
Actually there may be a way, now that I think about it:

cd
git clone git://git.debian.org/git/collab-maint/nodejs.git
cd nodejs
./configure --prefix /usr/bin
make
make install

I will test and see if this works

@leojh
Copy link

@leojh leojh commented Oct 7, 2017

I uninstalled node from WIndows and then installing nvm worked fine inside of Bash for Windows

@Shipwreck
Copy link

@Shipwreck Shipwreck commented Dec 4, 2017

@phucanhapril solution worked for me on WSL. I also have npm installed alongside on Windows.

Thanks for the help.

@zaidrashid
Copy link

@zaidrashid zaidrashid commented Dec 4, 2017

@phucanhapril , correct me if I'm wrong but your solution is to install a newer NPM in the Bash environment correct?

Is there a way to maintain the node installed in Windows, while making it work on Bash too?

@Shipwreck
Copy link

@Shipwreck Shipwreck commented Dec 4, 2017

Hi @zaidrashid I can confirm that npm is installed in Windows and WSL. I followed @phucanhapril process.

If I open a Windows terminal and call npm I get:
npm@5.5.1 C:\Program Files\nodejs\node_modules\npm

Then I bash into WSL and call npm and get:
npm@3.10.10 /usr/lib/node_modules/npm

Am realizing now that I may have some issues with versions, but they do appear to be working independently.

@mfominov
Copy link

@mfominov mfominov commented Jan 15, 2018

Hi, i used @felipemanga solution but made modification in npm srcipt:
case uname -a |grep Microsoft in
Microsoft) NODE_EXE="$basedir/node"
;;
*)
NODE_EXE="$basedir/node.exe"
if ! [ -x "$NODE_EXE" ]; then
NODE_EXE=node
fi
;;
esac
than i have to convert npm scrip to LF, and everything works:
mfominov@MFOMINOV:/mnt/c/Users/mfominov/source$ npm -v
5.5.1

@whindes
Copy link

@whindes whindes commented Jan 24, 2018

Hello @mfominov, I also used @felipemanga 's script but could not get the npm script to work. Here is the full npm script:

(set -o igncr) 2>/dev/null && set -o igncr; # cygwin encoding fix

basedir=`dirname "$0"`

case `uname` in
    *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

NODE_EXE="$basedir/node.exe"
if ! [ -x "$NODE_EXE" ]; then
  NODE_EXE=node
fi

NPM_CLI_JS="$basedir/node_modules/npm/bin/npm-cli.js"

case `uname -a` in
  *MINGW*)
    NPM_PREFIX=`"$NODE_EXE" "$NPM_CLI_JS" prefix -g`
    NPM_PREFIX_NPM_CLI_JS="$NPM_PREFIX/node_modules/npm/bin/npm-cli.js"
    if [ -f "$NPM_PREFIX_NPM_CLI_JS" ]; then
      NPM_CLI_JS="$NPM_PREFIX_NPM_CLI_JS"
    fi
    ;;
  *CYGWIN*)
    NPM_PREFIX=`"$NODE_EXE" "$NPM_CLI_JS" prefix -g`
    NPM_PREFIX_NPM_CLI_JS="$NPM_PREFIX/node_modules/npm/bin/npm-cli.js"
    if [ -f "$NPM_PREFIX_NPM_CLI_JS" ]; then
      NPM_CLI_JS="$NPM_PREFIX_NPM_CLI_JS"
    fi
    ;;
  *Microsoft*)
    NPM_PREFIX=`"$NODE_EXE" "$NPM_CLI_JS" prefix -g`
    NPM_PREFIX_NPM_CLI_JS="$NPM_PREFIX/node_modules/npm/bin/npm-cli.js"
    if [ -f "$NPM_PREFIX_NPM_CLI_JS" ]; then
      NPM_CLI_JS="$NPM_PREFIX_NPM_CLI_JS"
    fi
    ;;
esac

"$NODE_EXE" "$NPM_CLI_JS" "$@"

node -v works great, however, this is the output that I am getting for npm -v
net.js:200
this._handle.open(options.fd);
^

Error: EINVAL: invalid argument, uv_pipe_open
at new Socket (net.js:200:18)
at createWritableStdioStream (internal/process/stdio.js:164:16)
at process.getStdout [as stdout] (internal/process/stdio.js:14:14)
at console.js:246:38
at NativeModule.compile (bootstrap_node.js:596:7)
at Function.NativeModule.require (bootstrap_node.js:541:18)
at setupGlobalConsole (bootstrap_node.js:310:41)
at startup (bootstrap_node.js:70:7)
at bootstrap_node.js:608:3

@michaelyohanes
Copy link

@michaelyohanes michaelyohanes commented Oct 3, 2019

it happens to me a while ago, for having both NPM installed on windows & WSL.

Root cause:
This happens due to npm windows tries to run on linux environment.

Method to check

try to run which npm on WSL console, it is showing ...\Program Files.. then problem is there.

Solution 1:

Simply restart the WSL (reopening the window) will solve it.

Solution 2:

Try to add correct npm (linux) into the $PATH by exporting it will permanently solve it.

@hanpari
Copy link

@hanpari hanpari commented Oct 21, 2019

Just restarting the command promp after the node installation on the bash resolved this error for me.

This one should be pinned on the top. It worked for me as well.

@yuribreion1
Copy link

@yuribreion1 yuribreion1 commented Oct 22, 2019

Yes, just repeating the process in my third time fix the problem.

@nsdevaraj
Copy link

@nsdevaraj nsdevaraj commented Oct 25, 2019

Just follow the steps to install nvm mentioned here : https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-debian-9

It will fix npm issue by altering the profile

@ddtramp
Copy link

@ddtramp ddtramp commented Nov 25, 2019

need reinstall nodejs, and everything's fine

using

nvm install v10.17.0

`
whereis npm

npm: /usr/bin/npm /usr/share/npm /home/jack/.nvm/versions/node/v10.17.0/bin/npm /mnt/c/Program Files/nodejs/npm /mnt/c/Program Files/nodejs/npm.cmd /usr/share/man/man1/npm.1.gz

which npm

/home/jack/.nvm/versions/node/v10.17.0/bin/npm
`

@isakal
Copy link

@isakal isakal commented Nov 29, 2019

I fixed it by doing:

sudo apt install npm

and editing my .bashrc

alias npm='usr/bin/npm'

then sourced it:

. .bashrc

and now it works like a charm

$ npm

Usage: npm <command>

where <command> is one of:
    access, add-user, adduser, apihelp, author, bin, bugs, c,
    cache, completion, config, ddp, dedupe, deprecate, dist-tag,
    dist-tags, docs, edit, explore, faq, find, find-dupes, get,
    help, help-search, home, i, info, init, install,
    install-test, issues, it, la, link, list, ll, ln, login,
    logout, ls, outdated, owner, pack, ping, prefix, prune,
    publish, r, rb, rebuild, remove, repo, restart, rm, root,
    run-script, s, se, search, set, show, shrinkwrap, star,
    stars, start, stop, t, tag, team, test, tst, un, uninstall,
    unlink, unpublish, unstar, up, update, upgrade, v, verison,
    version, view, whoami

npm <cmd> -h     quick help on <cmd>
npm -l           display full usage info
npm faq          commonly asked questions
npm help <term>  search for help on <term>
npm help npm     involved overview

Specify configs in the ini-formatted file:
    /home/saki/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

npm@3.5.2 /usr/share/npm
@MauroNavaLuevanos
Copy link

@MauroNavaLuevanos MauroNavaLuevanos commented Nov 30, 2019

Just, run as administrator

@EduMOliveira
Copy link

@EduMOliveira EduMOliveira commented Dec 4, 2019

I fixed it by doing

$ sudo apt-get update
$ sudo apt-get install -y nodejs
$ sudo apt-get install build-essential
$ sudo apt get install npm
**CLOSE AND REOPEN TERMINAL**
@Pablosky12
Copy link

@Pablosky12 Pablosky12 commented Jan 14, 2020

I found out this was due to me trying to run an older version of Node/npm. I fixed it by updating my node version to the latest following this thread https://askubuntu.com/questions/426750/how-can-i-update-my-nodejs-to-the-latest-version

@seven-mile
Copy link

@seven-mile seven-mile commented Feb 21, 2020

I think changing $PATH manually is kind of ugly, so I choose to close the interoperability of WSL with Windows. After doing this, $PATH has turned really simple, away from conflicts. <3
Document

@UtkarshKr007
Copy link

@UtkarshKr007 UtkarshKr007 commented Mar 18, 2020

I fixed it by doing

$ sudo apt-get update
$ sudo apt-get install -y nodejs
$ sudo apt-get install build-essential
$ sudo apt get install npm
**CLOSE AND REOPEN TERMINAL**

This did it for me. Thank you!

@raphyphy
Copy link

@raphyphy raphyphy commented Apr 3, 2020

I fixed it by doing

$ sudo apt-get update
$ sudo apt-get install -y nodejs
$ sudo apt-get install build-essential
$ sudo apt get install npm
**CLOSE AND REOPEN TERMINAL**

I am using Ubuntu 18.04 subsystem for windows 10 and this fixed it for me. Thank you very much!

@xtianus79
Copy link

@xtianus79 xtianus79 commented Apr 12, 2020

@Georg-W can I buy you a beer man? lol all this freaking out all this searching. I think it could of been a combination of you and @abhijithvijayan

@abhijithvijayan
Copy link

@abhijithvijayan abhijithvijayan commented Apr 12, 2020

Glad it helped.

@supermavster
Copy link

@supermavster supermavster commented Apr 19, 2020

Hello is easy, if you Using Ubuntu on WSL (zsh/hyper)

First: Remove and Install Again Node

sudo apt-get --purge remove node
sudo apt-get --purge remove nodejs
curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo apt install node
sudo apt-get install -y build-essential

Second: Open and editthe .zshrc from the oh-my-zsh. vim ~/.zshrc

Find the line

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

And replace with:

# If you come from bash you might have to change your $PATH.
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

The last step is to reset your config: source ~/.zshrc

Test if this post works for you.

npm -v
node -v
@Compiler-Error
Copy link

@Compiler-Error Compiler-Error commented May 2, 2020

Ran into this wsl npm headache today. If other solutions did not work for you, this is what I did.
For this example, it is important to understand what the goal is for this case so you can use this example to show the error exists, do the fixes, and see if it fixed it for you as well.

$ cat broken.js
const puppeteer = require('puppeteer-core');

$ node broken.js
# Some errors related to "Cannot find module puppeteer-core"

$ npm i install  puppeteer-core
# Some errors, maybe something related to package.json 
# After a few hours, I begin to doubt my career choice.

1- optional.. UNINSTALL ubuntu wsl but don't forget to Run history first and back up your files.
2- Go to the microsoft store and search for Linux. Choose the Microsoft provided Debian wsl.
3- sudo apt update
4- sudo apt upgrade
5- sudo apt install wget
6- wget https://nodejs.org/dist/v12.16.3/node-v12.16.3-linux-x64.tar.xz
7- Read this install guide
https://github.com/nodejs/help/wiki/Installation#how-to-install-nodejs-via-binary-archive-on-linux
8 - sudo mkdir -p /usr/local/lib/nodejs
9- sudo tar -xJvf node-v12.16.3-linux-x64.tar.xz -C /usr/local/lib/nodejs
might also need this for tar..sudo apt-get install xz-utils
10- Put this on the last line of your ~/.profile file

$ export PATH=/usr/local/lib/nodejs/node-v12.16.3-linux-x64/bin:$PATH

Run this to update your terminal

$ . ~/.profile

11- which node
12- which npm
13- sudo apt install dos2unix
14- dos2unix broken.js
15- npm i puppeteer-core
16- node broken.js

Twitter is the best way to reach me. I think those are all the steps, but ping me @mabrafoo if needed.

@john-lamontagne
Copy link

@john-lamontagne john-lamontagne commented May 6, 2020

hi y'all, here's how i got my stuff working. i'm on ubuntu for windows 10 (on a windows VM--i don't think the VM part matters though). i was getting the same errors as @RichiCoder1

$ npm -v
: not foundram Files/nodejs/npm: 3: /mnt/c/Program Files/nodejs/npm:
: not foundram Files/nodejs/npm: 5: /mnt/c/Program Files/nodejs/npm:
/mnt/c/Program Files/nodejs/npm: 6: /mnt/c/Program Files/nodejs/npm: Syntax error: word unexpected (expecting "in")

i have node installed for windows (off the nodejs site). i kept it around, and in addition i followed @mrtopf's install instructions

$ curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
$ sudo apt-get install -y nodejs

then i made some changes to my PATH in my ~/.profile

PATH="$HOME/bin:$HOME/.local/bin:/usr/bin:$PATH"

and sourced it source ~/.profile

what i'm doing up there is telling bash where & in what order to look for my commands, separated by : so i'm saying first look in $HOME/bin then $HOME/.local/bin etc.

you should which npm and use the path where your ubuntu npm is. here's mine:

$ which npm
/usr/bin/npm

so i added /usr/bin to my PATH. /usr/bin needs to go BEFORE $PATH. i check that everything's OK now

$ whereis npm
npm: /usr/bin/npm /mnt/c/Program Files/nodejs/npm /mnt/c/Program Files/nodejs/npm.cmd

bash will use /usr/bin/npm before the npm in Program Files
now i can npm install with no problems :-)

Hello from the future, you are an absolute legend! this fixed an issue with npm on WSL which I had been trying to resolve for days.

I followed your instructions, and tried npm i for the 50th time, but this time, it worked!!

@leontepe
Copy link

@leontepe leontepe commented May 24, 2020

@zaidrashid

Is there a way to maintain the node installed in Windows, while making it work on Bash too?

Did anybody find a solution for this? I would like to just use my Node installation on Windows if that is possible. That would be the most elegant and efficient solution.

@odolha
Copy link

@odolha odolha commented Jun 25, 2020

I just used /usr/bin/npm instead of npm when running it :P, e.g. /usr/bin/npm install. Seemed to work.

@thuong-resper
Copy link

@thuong-resper thuong-resper commented Jul 11, 2020

I ran into a variation of this problem where after following steps here, I still got the error:

: not foundram Files/nodejs/npm: 3: /mnt/c/Program Files/nodejs/npm:
: not foundram Files/nodejs/npm: 5: /mnt/c/Program Files/nodejs/npm:
/mnt/c/Program Files/nodejs/npm: 6: /mnt/c/Program Files/nodejs/npm: Syntax error: word unexpected (expecting "in")

whereis npm did not show /usr/bin. Running sudo apt-get install npm did the trick.

Oh my god, really appreciate, Just 1 line of code, solved my problem

@al3xr3is
Copy link

@al3xr3is al3xr3is commented Oct 8, 2020

I had this problem, caused by not running with sudo. try to run with administrator privileges.

@therealkenc
Copy link
Collaborator

@therealkenc therealkenc commented Oct 8, 2020

I had this problem, caused by not running with sudo. try to run with administrator privileges.

By running sudo you have eliminated your Windows install of node/npm from your Linux $PATH. It had nothing to do with with root privileges.

image

@stefek99
Copy link

@stefek99 stefek99 commented Oct 21, 2020

Installing nvm: https://github.com/nvm-sh/nvm#installing-and-updating

Solves the npm problem for me.

(will see how many other problems I will encounter along the way)

@shiyuw
Copy link

@shiyuw shiyuw commented Nov 1, 2020

I met this problem in WSL and my directory is 'C:\Program Files\nodejs'. When I moved nodejs directory to C (C:\nodejs), npm works well.

@BluelyTASer
Copy link

@BluelyTASer BluelyTASer commented Dec 6, 2020

using sudo before npm solves the problem!
406

@dkcamargox
Copy link

@dkcamargox dkcamargox commented Dec 24, 2020

hi y'all, here's how i got my stuff working. i'm on ubuntu for windows 10 (on a windows VM--i don't think the VM part matters though). i was getting the same errors as @RichiCoder1

$ npm -v
: not foundram Files/nodejs/npm: 3: /mnt/c/Program Files/nodejs/npm:
: not foundram Files/nodejs/npm: 5: /mnt/c/Program Files/nodejs/npm:
/mnt/c/Program Files/nodejs/npm: 6: /mnt/c/Program Files/nodejs/npm: Syntax error: word unexpected (expecting "in")

i have node installed for windows (off the nodejs site). i kept it around, and in addition i followed @mrtopf's install instructions

$ curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
$ sudo apt-get install -y nodejs

then i made some changes to my PATH in my ~/.profile

PATH="$HOME/bin:$HOME/.local/bin:/usr/bin:$PATH"

and sourced it source ~/.profile

what i'm doing up there is telling bash where & in what order to look for my commands, separated by : so i'm saying first look in $HOME/bin then $HOME/.local/bin etc.

you should which npm and use the path where your ubuntu npm is. here's mine:

$ which npm
/usr/bin/npm

so i added /usr/bin to my PATH. /usr/bin needs to go BEFORE $PATH. i check that everything's OK now

$ whereis npm
npm: /usr/bin/npm /mnt/c/Program Files/nodejs/npm /mnt/c/Program Files/nodejs/npm.cmd

bash will use /usr/bin/npm before the npm in Program Files
now i can npm install with no problems :-)

YOU FUCKING GENIUS GENIUS

@dharm1k987
Copy link

@dharm1k987 dharm1k987 commented Jan 9, 2021

All of the replies above seem to be installing npm on WSL. If you don't want to install nodejs on WSL, and instead want to run the Windows counterpart, then these steps worked for me:

First of all note that since the Windows 10 Creators Update (build 1703, April 2017), we can natively run .exe files through WSL. You can try this by typing ipconfig.exe, or cmd.exe, and see both of them execute fine (given that you didn't remove the Windows path that is automatically prepended) . If you have nodejs installed on Windows, you can even run node.exe, and it should work fine.

The problem is that all of these are .exe files. npm is an exception, as are all global node modules. If you go to /mnt/c/Program Files/nodejs, you will notice that npm is written as npm.cmd. You cannot run .cmd files from WSL as per my knowledge.

The way I go around this is by running:

cmd.exe /c npm.cmd in the current location. You should see output then.

You will notice that with your global node modules (inside /mnt/c/Users/<USERNAME>/AppData/Roaming/npm), you will not be able to call them from WSL either. Again, this is because they are .cmd instead of .exe.

We must create alias for these again if you want to use them through WSL. You can actually do this easily programmatically in your ~/.bashrc file:

Full solution:

cmd() {
  CMD=$1
  shift;
  ARGS=$@
  WIN_PWD=`wslpath -w "$(pwd)"`
  cmd.exe /c "pushd ${WIN_PWD} && ${CMD} ${ARGS}"
}

alias npm="cmd npm"

for file in `ls /mnt/c/Users/<USERNAME>/AppData/Roaming/npm/[a-z]*.cmd`; do
	cmdFile=$(basename -- "$file")
	filename="${cmdFile%.*}"
	alias "$filename"="cmd ${cmdFile}"
done

The reason we need the pushd command in cmd is because we need cmd to keep the same path as we had on WSL.

After restarting your terminal, you should be able to run npm --version and global commands like ng easily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet