[rush] incorrect Node.js version detection
Summary
Any rush command fails, because of node.js version validation.
$ node --version
v14.20.0
$ rush --debug update
Rush Multi-Project Build Tool 5.56.0 - https://rushjs.io
Node.js version is 16.16.0 (LTS)
ERROR: Your dev environment is running Node.js version v16.16.0 which does not meet the requirements for building this repository. (The rush.json configuration requires nodeSupportedVersionRange=">=12.13.0 <13.0.0 || >=14.15.0 <15.0.0")
Repro steps
Using Nixos:
- Enter a nix-shell where nodejs is v16.16.0.
- Then enter another nix-shell where nodejs is v14.20.0
- Run any rush command.
Details
Rush is not detecting nodejs verison by actually running node --version.
Standard questions
Please answer these questions to help us investigate your issue more quickly:
| Question | Answer |
|---|---|
@microsoft/rush globally installed version? |
5.76.1 |
rushVersion from rush.json? |
5.56.0 |
useWorkspaces from rush.json? |
Yes |
| Operating system? | Linux:Nixos |
| Would you consider contributing a PR? | No |
Node.js version (node -v)? |
16.16.0 then 14.20.0 |
How is Rush installed globally? What is the contents of the file at the path that gets printed when you run which rush?
My suspicion is that the bin script for Rush is pointing at a different version of Node.
Rush is globally installed via nix-shell & node2nix. At the time of running node2nix, node version is specified (as 16). This somehow constraints the node versions when spawned by rush. Regardless of the node version available in the user's shell.
I'm also getting this. In my case, I used devbox to create a development shell which specifies node and rush to be globally installed in the shell. Devbox is also a nix shell, so I believe my issue is the same as this one.
In my config for devbox, I initially specified the latest version of node, but it was not compatible, so I re-created the shell with older version of node, but it's still pointing to the wrong node version.
@gomain Did you figure out how to fix this?
@iclanton When I do which rush, I get this:
/home/<username>/<path-to-project-dir>/.devbox/nix/profile/default/bin/rush
When I see the content of the file, I see this.
#!/nix/store/vz13mi0w75q96sfjxz2ylnv8812hvf34-nodejs-20.11.1/bin/node
require('../lib/start.js');
Running /nix/store/vz13mi0w75q96sfjxz2ylnv8812hvf34-nodejs-20.11.1/bin/node -v returns a wrong version. This may not be a rush related issue, but it's odd that it's referring to a wrong node.
Rush just uses whichever version of Node it was Invoked with, so if it's getting an unexpected version, I'd guess it's because either the package manager that installed it generated an incorrect bin file, or it was installed with under a different version of node in a location that's available to all versions of node.
Given that this seems to be happening on/with nix, I bet nix doesn't isolate globally installed packages from between node versions. I'd consider this a flaw with nix, since packages that have native bindings often need those bindings to match a specific version of Node. You should be able to mitigate this by reinstalling Rush globally.
nix ensures runtime dependencies. executable node packages (such as rush) executables aren't plain scripts run by the node available at the shell, but a node specified by its derivative. this is particularly true when derivatives were generated via node2nix. you could install rush without installing node and it will still run. this is not a bug. you need tobe explicit of what you want.
@gomain Got it. That's a good point. I'm still fairly new to nix, but I understand what you mean.
@iclanton I suppose this ticket can be closed since it's not a problem with rush.