vscode-viva icon indicating copy to clipboard operation
vscode-viva copied to clipboard

🐞 Bug report: Using sample throws nvm use error on Windows without version argument.

Open Saurabh7019 opened this issue 7 months ago β€’ 1 comments

⭐ Priority

(Low)☹️ Something is a little off

πŸ“ Describe the bug

When creating a new SPFx project via the sample gallery, a new VS Code instance opens and a terminal is automatically created. If the project contains a .nvmrc file, the logic currently sends nvm use to the terminal. But, this causes the following issue:

Image

πŸ‘£ Steps To Reproduce

  • Use the SPFxToolkit extension to create a new SPFx project from sample gallery
  • On Windows with nvm-windows, check the terminal output
  • Observe the warning from nvm use

πŸ“œ Expected behavior

nvm use should run with the version from .nvmrc file

πŸ“· Screenshots

No response

❓SharePoint Framework Toolkit version

No response

❓Node.js version

v4.8.0

πŸ€” Additional context

Image

This should be updated to read the version from .nvmrc and pass as an argument to nvm use

Saurabh7019 avatar Jun 11 '25 16:06 Saurabh7019

aaaa I totally forgot about that πŸ˜‚... yes this was a known issue I forgot to take care of that. The problem here is that nvm use does not support .nvmrc file when using nvm-windows. On linux or Mac it just works, so it finds the .nvmrc file and based on the version there set the correct version when just running nvm use command. And that is partially the reason why I forgot about this issue as I primary use WSL when doing SPFx stuff 😁

Anyway, since you brought it up now πŸ‘πŸ‘πŸ‘ let's get this fixed: The thing you suggested is 100% correct approach, so lets create some additional logic on SPFx Toolkit side to parse the version in .nvmrc and run the nvm use <version> command which will work both in Windows and 'non-windows' machines 😜. One thing I don't like about it is that we are enhancing a product outside of SPFx Toolkit scope, I mean we are fixing up nvm-windows adding a feature which just should be there but I am fine with that.

One thing on top of that we could fix up along the way is the line const nvmFiles = await workspace.findFiles('.nvmrc', '**/node_modules/**'); the problem here is that when using nvs (which BTW is way better if you are using windows for dev) you may either use .nvmrc files (which is most popular) BUT it also supports .node-version file to keep the version of node which should be used in the project. What we could do is:

  • if the dev has nvs set as primary node version manager in SPFx Toolkit setting, then we should look either for .nvmrc or .node-version as both ar supported in this case and nvs use just works also on windows in this case, we don't need to pass the version to the command. When nvm is set in the SPFx Toolkit setting then we should just look for .nvmrc file.

Other than that. lets get this fixed πŸš€

Adam-it avatar Jun 11 '25 21:06 Adam-it