New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support .nvmrc #128
Comments
I don't think this is a route I want to go down. The primary reason is it would require some very ugly hacking to recreate/mimic the node binary. For example, calling Some other similar projects have attempted to use I also just don't think the demand is widespread for this. |
The .nvmrc support is a fairly important aspect of using NVM with a CI system. I don't link the package.json suggestion, especially as it breaks compatibility with nvm, but would a pull request with support for .nvmrc be accepted? |
@gruber76 - I probably won't accept a PR on this.
|
@coreybutler I'm not sure I understand your rationale for not wanting to support this. Wouldn't having this feature simply fallback to looking into the .nvmrc file whenever nvm is invoked without specifying a version number? Hence, what nasty hacks are you talking about? |
The nasty hack: rewrite symlinks for Windows. NVM for Windows works by changing the symlink target to the desired physical node installation directory. This is a system-wide change. Let's say you fire up a script by specifying version 0.12.0 in a The only way to truly isolate a version on a per-process basis is to have If people really want to use a per-process/project approach, a more appropriate solution is isolating the runtime environment. Personally, I use Docker for that. |
Forgive me for my ignorance, here. My primary use case is developing node/web applications using bower/grunt/gulp, etc. with multiple teams. For me, it is extremely rare that I would have multiple versions running within five minutes of each other. For this use case, the .nvmrc file is how my teams specify what node should be doing. I'm having trouble seeing in the situation you describe (script A versus script B) how supporting .nvmrc would be any more troublesome than having script A (or a user of script A) calling nvm to set the version and then forgetting to set it before running script B. But I'm guessing there are some common use cases for nvm that are much harder core than mine. Possibly, for instance, if my CI servers had a heavier load. I do have a hackey workaround to offer up to anyone else who needs it. The following in a pre-run bat script:
|
Why not put the nvm command to set the required version in a npm script? Steve Lee
|
Supporting the As a side note, it's also kind of annoying that Our work-around for this is that we have a file named var childProcess = require('child_process')
var fs = require('fs')
var nodeVersion = fs.readFileSync('.nvmrc', 'utf8').trim()
var command = "nvm install " + nodeVersion + " && nvm use " + nodeVersion
console.log('executing command: ' + command)
childProcess.exec(command, function(error, stdout, stderr) {
if (stdout) console.log(stdout.toString())
if (stderr) console.error(stderr.toString())
if (error) console.error(error)
}) |
@josh-egan-ps - The separation between For everyone - If you really need to switch on a per-project basis, consider putting |
That might actually be too late in the case any npm build scripts used during install that depend on node / npm version. Or other tools such as grunt etc run expicitly They could fail during install with the wrong version of node / npm. or use the wrong version causing other problems, BTW I'm assuming the other best practice of having everything locally installed (ie not -g) so version dependencies are never a problem. Thus it's good practice to use the "preinstall": "nvm use x.x.x", That should be OK even if the original npm version will be running in the parent process. The install step will launch a new shell so all actions should pick up the new node and npm. You might even want to add a pre start step than installs. |
@SteveALee - yeah, you're right, my earlier suggestion wouldn't work. It would be too late in the process to launch reliably. |
@coreybutler In the end I went for this "preinstall":"nvm use 4.4.1 || echo nvm not found: check node version && pause", |
Perhaps a |
I would like to suggest to implement a part of this at least: On Linux / Mac, in a folder with a I combine this on my systems with a script that overloads # Support .nvmrc
load-nvmrc() {
if [[ -f .nvmrc && -r .nvmrc ]]; then
nvm use
elif [[ $(nvm version) != $(nvm version default) ]]; then
echo "Reverting to nvm default version"
nvm use default
fi
}
# Override `cd` to auto-load correct version of Node on enterting directory.
cd() { builtin cd "$@"; 'load-nvmrc'; } This could easily work on Windows too, if |
Since this issues seems to be nearly dead, I've got a workaround Powershell script that should mimic the functionality of "nvm use" and "nvm install" if the .nvmrc file contains a single digit node version.
@coreybutler If you updated the "use" command in nvm.go to use the same code as The following script will use "nvm list available" and filter the list for the highest LTS version that matches the .nvmrc file's version and then 'nvm use' it. If it is not installed, it 'nvm install's it then 'nvm use' it. |
Just want to request the support of nvm use to read from an .nvmrc file. It would really make my node development experience between Mac and Windows to be seamless. |
Is this closed because it was fixed or is not going to be changed? Is there another Windows-compatible version of |
|
@KevinGhadyani-minted This was closed because it will not be added. For Everyone: There are too many variations of different shells on Windows to support this with a script. For example, There are no direct ports of the original nvm on Windows. While I understand the desire to have the same tool between mac and Windows, they are different platforms. In the early days, I attempted to provide some parity with nvm (which is why the tool is called NVM for Windows, a poor naming choice). However; the development patterns required to support each OS don't always translate very well, because none of the version managers were designed specifically for cross-platform use. I develop extensively on mac, Windows, and Linux and believe there are better ways to manage JavaScript runtimes than the approaches implemented in any current version managers. This is why I'm working on "rt", a runtime manager to succeed NVM4W. See #565 for more details. The truth is the pandemic hurt the pace of my business ventures and sponsorships aren't putting food on the table. As much as I'd like to promise a release date, I can't. The only thing I will mention is I finally ordered a new Windows computer, so I will be able to put a little more effort into "rt" once that arrives. |
Alows project to speicify the version to be used.
See nvm usage
or perhaps parse closet available version from package.json engines
The text was updated successfully, but these errors were encountered: