π Bug report: Using sample throws nvm use error on Windows without version argument.
β 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:
π£ 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
This should be updated to read the version from .nvmrc and pass as an argument to nvm use
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
nvsset as primary node version manager in SPFx Toolkit setting, then we should look either for.nvmrcor.node-versionas both ar supported in this case andnvs usejust works also on windows in this case, we don't need to pass the version to the command. Whennvmis set in the SPFx Toolkit setting then we should just look for.nvmrcfile.
Other than that. lets get this fixed π