node.jsnpmnext.jsnode-moduleswindows-subsystem-for-linux

npm on Windows keeps requiring WSL


I am trying to run my NPM projects on Windows, but when I run npm run dev, it keeps asking me to install WSL, even though I don't want to use it. Here’s what happens:

C:\{Path}\GitHub\project> npm run dev

> project@0.1.0 dev   
> next dev --turbopack

This application requires the Windows Subsystem for Linux Optional Component.
Install it by running: wsl.exe --install --no-distribution
The system may need to be restarted so the changes can take effect.
Error code: Bash/WSL_E_WSL_OPTIONAL_COMPONENT_REQUIRED

The issue also happens when running npx

PS C:\Path\to\test> npx create-react-app my_app

This application requires the Windows Subsystem for Linux Optional Component.
Install it by running: wsl.exe --install --no-distribution
The system may need to be restarted so the changes can take effect.
Error code: Bash/WSL_E_WSL_OPTIONAL_COMPONENT_REQUIRED

(this started happening after a windows update)

My Questions:

What I tried:

System Info:


Solution

  • Try first reset npm/nodejs path resolution

    run

    npm config get script-shell
    

    to check your npm configuration and see where it's pointing at..

    and then run:

    npm config set script-shell "C:\\Windows\\System32\\cmd.exe"
    

    this will reset npm to use Windows command processor.. Change the C: with your right windows installation. And also check your PATH environment variable to see if its running in the right path, usually: C:\Program Files\nodejs\ yourWslPath run in power shell

    $env:PATH -split ";"
    

    and see the result..

    You can test this by running in terminal:

    $env:PATH = "C:\Program Files\nodejs\;$env:PATH"
    npm run dev
    

    and see if works.. The problem probably is that with the update your path may have been linked to a older version..