4

My question is related to In WSL2: Ubuntu 20.04 for Windows 10 nodejs is installed but npm is not working

I faced the same problem, which I resolved by converting the line endings to Unix style. But then, running the command starts failing with this:

mark@L-R910LPKW:~$ npm -v
internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module '\\wsl.localhost\Ubuntu-20.04\mnt\c\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
mark@L-R910LPKW:~$

Which surfaces an interesting file path - \\wsl.localhost\Ubuntu-20.04\mnt\c\Program Files\nodejs\node_modules\npm\bin\npm-cli.js

So \\wsl.localhost\Ubuntu-20.04 actually references the root of the Linux distro when examined from Windows:

C:\> dir \\wsl.localhost\Ubuntu-20.04


    Directory: \\wsl.localhost\Ubuntu-20.04


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----         10/6/2022   6:27 PM                home
d-----         4/23/2020   2:40 AM                srv
d-----         10/7/2022   3:18 PM                .certs
d-----         10/7/2022   4:41 PM                etc
d-----         4/23/2020   2:40 AM                opt
d-----         10/7/2022   4:41 PM                root
d-----         10/6/2022   6:27 PM                mnt
d-----         4/23/2020   2:41 AM                usr
d-----         4/23/2020   2:40 AM                media
d-----         10/6/2022  10:21 PM                sys
d-----         10/6/2022  10:21 PM                dev
d-----         4/23/2020   2:49 AM                boot
d-----         10/6/2022  10:27 PM                run
d-----         10/6/2022  10:21 PM                proc
d-----         4/10/2020  10:57 AM                snap
d-----         10/7/2022   3:50 PM                tmp
d-----         4/23/2020   2:43 AM                var
d-----         4/10/2019  12:35 PM                lost+found
-----l         4/23/2020   2:40 AM              7 lib
-----l         4/23/2020   2:40 AM              9 lib64
-----l         4/23/2020   2:40 AM              8 sbin
-----l         4/23/2020   2:40 AM              7 bin
-----l         4/23/2020   2:40 AM              9 lib32
-----l         4/23/2020   2:40 AM             10 libx32
------         6/18/2022   4:36 AM        1392928 init


C:\>

And /mnt/c is where the C: drive is mounted under Linux:

mark@L-R910LPKW:~$ ls /mnt/c
ls: cannot access '/mnt/c/DumpStack.log.tmp': Permission denied
ls: cannot access '/mnt/c/hiberfil.sys': Permission denied
ls: cannot access '/mnt/c/pagefile.sys': Permission denied
ls: cannot access '/mnt/c/swapfile.sys': Permission denied
'$Recycle.Bin'                     DumpStack.log      'Program Files (x86)'         Users          log
'$WINRE_BACKUP_PARTITION.MARKER'   DumpStack.log.tmp   ProgramData                  Windows        node-modules-cache
'$WinREAgent'                      Graphviz            Recovery                     cygwin         pagefile.sys
'Ceridian Software'                ILSpy               Shared                       cygwin64       swapfile.sys
 Config.Msi                        Intel               Symbols                      dayforce       tenorshare
 DBBackups                         NDepend            'System Volume Information'   docker         totalcmd
 DRIVERS                           PerfLogs            Temp                         hiberfil.sys   utils
'Documents and Settings'          'Program Files'      Ubuntu                       lfs            work
mark@L-R910LPKW:~$

So \\wsl.localhost\Ubuntu-20.04\mnt\c\Program Files\nodejs\node_modules\npm\bin\npm-cli.js is essentially C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js, which definitely exists:

C:\> dir "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js"


    Directory: C:\Program Files\nodejs\node_modules\npm\bin


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----          4/6/2021   3:07 PM           4861 npm-cli.js


C:\>

However, there is a disconnect - the directory \\wsl.localhost\Ubuntu-20.04\mnt\c is inaccessible from Windows:

C:\> dir \\wsl.localhost\Ubuntu-20.04\mnt


    Directory: \\wsl.localhost\Ubuntu-20.04\mnt


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----         10/6/2022  10:21 PM                wsl
d-----         10/7/2022   4:28 PM                wslg
d-----         10/7/2022   7:19 AM                c


C:\> dir \\wsl.localhost\Ubuntu-20.04\mnt\c
dir : Access is denied
At line:1 char:1
+ dir \\wsl.localhost\Ubuntu-20.04\mnt\c
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (\\wsl.localhost\Ubuntu-20.04\mnt\c:String) [Get-ChildItem], Unauthor
   izedAccessException
    + FullyQualifiedErrorId : ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand

C:\>

But the other directories are accessible:

C:\> dir \\wsl.localhost\Ubuntu-20.04\mnt\wsl\


    Directory: \\wsl.localhost\Ubuntu-20.04\mnt\wsl


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----         10/6/2022  10:21 PM                docker-desktop-bind-mounts
d-----         10/6/2022  10:21 PM                docker-desktop
d-----         10/6/2022  10:21 PM                docker-desktop-data
------         10/6/2022  11:47 PM            122 resolv.conf


C:\>

The difference, as I see it, is that /mnt/c (and everything under it) is owned by my local Linux account whereas the others are owned by the root:

mark@L-R910LPKW:/mnt$ ls -l
total 0
drwxrwxrwx 1 mark mark 4096 Oct  7 07:19 c
drwxrwxrwt 5 root root  120 Oct  6 22:21 wsl
drwxrwxrwt 6 root root  260 Oct  7 16:28 wslg
mark@L-R910LPKW:/mnt$

I wonder if this is the real root cause and if so - what is the proper way to fix it assuming I want this particular path to be accessible from Windows.

I may remove the Windows paths from the Linux PATH entirely, but I want to learn how this stuff works and so it is important to me to understand what is going on and how to fix it.

mark
  • 59,016
  • 79
  • 296
  • 580

0 Answers0