Search code examples
node.jswindowsnpmyarnpkgnvm

NPM is choosing incorrect Node.js version for FE solution (on specific pc)


Locally I'm using nvm to manage Node.JS version; current node version is 18.19.0; I don't have ver. 12 installed. Before installing nvm - I have removed Node from computer, now I can't see it in "Add or remove programs".

I have a Single Page Application written on Svelte. When I'm navigating into project folder:

  • node -v is returning 18.19.0.
  • npm run nodever is returning 12.20.0. Here script "nodever": "node -v".
  • yarn run nodever is returning 18.19.0.
  • note: npm version is 10.2.5 in all scenarios (update to 10.7.0 haven't helped).

On my work computer problem is - while using npm my project is choosing node.js version that is not enabled, and not even (properly) installed on the computer. Build and test scripts also affected. On fresh virtual machine (and in ci/cd pipeline), the same project is using correct node version even with npm, so problem is not in solution itself but in some setup on work pc.

Attempts to fix:

  • reloading project from git into a new folder had no effect.
  • reinstalling nvm had no effect; installing and uninstalling node 12 in nvm also.
  • can't see anything suspicious in PATH: no mentions of node, only nvm.
  • npm cache clean --force had no effect.
  • npm install -g npm@latest (10.7.0) had no effect on node version.

My question is: What configuration could cause this problem? How/why npm could start choosing incorrect node.

Note: Using yarn is fine, but I'd like to figure out how did I manage to break npm so badly.


In case if it'll help - my PATH variables, for account and for system: Account:

%NVM_HOME%;%NVM_SYMLINK%;C:\Users\1\AppData\Local\Microsoft\WindowsApps;C:\Program Files\kdiff3;C:\Users\1\AppData\Local\GitHubDesktop\bin;C:\Nuget;C:\Users\1\AppData\Local\Programs\Fiddler;C:\Users\1.dotnet\tools;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;C:\Python27;C:\Python38;%USERPROFILE%.dotnet\tools;C:\Users\1\AppData\Local\Yarn\bin;%JetBrains Rider%;%USERPROFILE%\AppData\Local\Programs\Microsoft VS Code Insiders\bin;

System:

%NVM_HOME%;%NVM_SYMLINK%;C:\Python311\Scripts;C:\Python311;C:\Python310\Scripts;C:\Python310;C:\Python39\Scripts;C:\Python39;C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin;C:\Python38\Scripts;C:\Python38;C:\Python27;C:\Python27\Scripts;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\OpenSSH;C:\ProgramData\chocolatey\bin;C:\Program Files\Microsoft SQL Server\130\Tools\Binn;C:\Program Files\Microsoft VS Code\bin;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio;C:\Nuget;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn;C:\Program Files\Microsoft SQL Server\140\Tools\Binn;C:\Program Files\Microsoft SQL Server\140\DTS\Binn;C:\Users\1\AppData\Local\GitTfs;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn;C:\Program Files\Microsoft SQL Server\110\Tools\Binn;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn;C:\Program Files\Microsoft SQL Server\110\DTS\Binn;C:\Program Files\PuTTY;C:\Program Files (x86)\Yarn\bin;C:\Program Files\Microsoft\Azure Functions Core Tools;C:\Program Files\Microsoft SQL Server\150\Tools\Binn;C:\Program Files\dotnet;C:\Program Files\Docker\Docker\resources\bin;C:\Program Files (x86)\GitExtensions;C:\Program Files\Git\cmd;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\Program Files\PowerShell\7;C:\Program Files (x86)\PowerShell\7;


Solution

  • Npm automatically searching for node_modules in all parent folders and adding them to PATH with higher priority. One of the parent folders on my PC had node.exe with obsolete version.

    To simplify search: add script "path": "node -e \"console.log(process.env.PATH)\"", and run npm run path - it will return actual PATH that solution will use to resolve dependencies.


    This answer was posted as a comment to the question [resolved]NPM is choosing incorrect Node.js version for FE solution (on specific pc) by the OP user3190541 under CC BY-SA 4.0.