Skip to content
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

Honor .node-version file #794

Open
mnquintana opened this issue Aug 4, 2015 · 58 comments · May be fixed by #3351
Open

Honor .node-version file #794

mnquintana opened this issue Aug 4, 2015 · 58 comments · May be fixed by #3351
Labels
feature requests I want a new feature in nvm!

Comments

@mnquintana
Copy link

Forgive me if this has been discussed before, but I didn't find anything beyond #110 (comment).

It would be really nice to see the various Node version managing tools coalesce around a common "version config file", analogous to Ruby's .ruby-version for RVM and rbenv - .node-version. This would basically just be an alias for .nvmrc, since that functionality's already been added. Since n already supports .node-version, this would make it so that regardless of the Node version manager used, there could be some degree of guarantee that the correct version will be used.

@ljharb ljharb added the feature requests I want a new feature in nvm! label Aug 4, 2015
@ljharb
Copy link
Member

ljharb commented Aug 4, 2015

When did n add support for node-version?

Which would win if you had both files present?

What about the different version formats that nvm supports - ie, iojs, stable, node, or 0.10, etc - and how do other version managers interact with those? What special formats do they offer that nvm might be forced to interact with?

@mnquintana
Copy link
Author

When did n add support for node-version?

Ah sorry, my mistake, it wasn't n - it's avn and nodenv. I actually asked the Stack Overflow question about this awhile back.

Which would win if you had both files present?

I think I'd expect .nvmrc to win if both files were present, but I don't really have strong feelings about this.

What about the different version formats that nvm supports - ie, iojs, stable, node, or 0.10, etc - and how do other version managers interact with those? What special formats do they offer that nvm might be forced to interact with?

That's a good question - I'll have to research this a bit.

@ljharb
Copy link
Member

ljharb commented Aug 4, 2015

I'd never heard of nodenv, but avn alone isn't enough for it to be a "common" version file. Do note my answer on that question which I think is a bit better than the accepted one http://stackoverflow.com/a/29545541 :-)

@ljharb ljharb added the needs followup We need some info or action from whoever filed this issue/PR. label Aug 14, 2015
@mcandre
Copy link

mcandre commented Aug 24, 2015

+1

Rapid, per-project .ruby-version switching with rvm is too useful not to have this for Node.js!

@lpil
Copy link

lpil commented Sep 25, 2015

👍

@Ajedi32
Copy link

Ajedi32 commented Sep 25, 2015

I think the idea here is that even though .nvmrc already provides this functionality, having a more generic cross-implementation .node-version file would be beneficial.

As @ljharb pointed out though, interoperability here would require more than just a common filename. iojs, stable, node are also valid version numbers for nvm, but not necessarily for other implementations. I'm honestly not sure how that should be handled. Maybe some discussion with the maintainers of other node versioning-type projects is in order...

@ljharb
Copy link
Member

ljharb commented Sep 25, 2015

If all of nave, n, avn, and whoever else all wants to cleave to nvms "version-ish" format, or, at least is prepared to accept or reject it gracefully (for example, supporting a version number but not a generic tag), that's great. Note that soon I'll have release candidate support for io.js and node, and these will have a different prefix as well, and who knows what the future will bring?

@lalitkapoor
Copy link

Just for .nvmrc files - https://github.com/lalitkapoor/nvm-auto-switch - I appreciate any feedback. Thanks!

@ljharb
Copy link
Member

ljharb commented Jun 3, 2016

Please use github reactions on the original post rather than posting "+1". Fair warning, I'll clean up existing and future comments that simply say that.

@ljharb ljharb removed the needs followup We need some info or action from whoever filed this issue/PR. label Jul 20, 2016
@paulodiovani
Copy link

If all of nave, n, avn, and whoever else all wants to cleave to nvms "version-ish" format, or, at least is prepared to accept or reject it gracefully (for example, supporting a version number but not a generic tag), that's great.

That's not a problem, at all...

nvm could use .node-version as an alternative, but still giving preference to .nvmrc.

Project owners could decide to use a wider syntax on .node-version (just the version number, which, I think, it's most of cases) to allow use of any version manager OR use a specialized syntax and prefix on .nvmrc.

I don't even think nvm should care about which file is in use, but just parse .nvmrc or .node-version (in this order).

@epixa
Copy link

epixa commented Aug 7, 2016

I'm not sure if I even like this idea, but a generic approach to "supporting" node-version directly might be to support a syntax in nvmrc that allows people to read the version string from any other file.

// .nvmrc
file:.node-version

// .node-version
6.3.1

This approach does have some pleasant side effects:

  1. No chasing additional version "standards" once the precedent has been set by supporting .node-version
  2. No questions of precedence
  3. No need to hardcode any subtle differences in support between the two standards since you're essentially making the assumption that the other file is compatible with nvm rather than the other way around.

@ljharb
Copy link
Member

ljharb commented Aug 10, 2016

That's not a half-bad idea. However, file:.node-version is a valid alias name, so it'd probably have to be something with a slash in it.

I'll think about that one more.

@TylerBre
Copy link

TylerBre commented Oct 12, 2016

.node-version is a much more sane name than .nvmrc

furthermore, I don't see why it shouldn't support both

@ljharb
Copy link
Member

ljharb commented Oct 12, 2016

@TylerBre please don't use ableist terms like "sane".

node-version would work if it was a universal version identifier. However, nvm supports io.js, and aliases, neither of which are necessarily "node" or "universal".

@koenpunt
Copy link
Contributor

koenpunt commented Dec 22, 2016

Even though nvm support io.js, .node-version would still be relevant. And to be fair, nvm stands for "node version manager", and io.js isn't node, it's node compatible. That being said, I think it should be possible to honour .node-version for node versions, and maybe then also support .iojs-version, if that's still relevant for someone.

@ljharb
Copy link
Member

ljharb commented Dec 22, 2016

io.js is node, versions 1-3, after the fact.

You're also missing the most important part, which is "aliases".

@koenpunt
Copy link
Contributor

The purpose of .node-version is that you want a static, consistent version. Specifying an alias would defy that purpose.

@ljharb
Copy link
Member

ljharb commented Dec 22, 2016

I agree - which would mean that nvm respecting node-version would have to be limited to static versions only.

What do avn and nodenv support in node-version files? If it's just "a static version, with or without a leading v" then the possibility still remains open that nvm could support that too.

@koenpunt
Copy link
Contributor

nodenv differentiates between node and iojs with definitions like 0.10.36 and iojs-1.0.0 (as seen in their README). And it requires that exact version to be installed.
Installing of that version can be done by running nodenv install (with the node-build plugin added).

@ljharb
Copy link
Member

ljharb commented Dec 22, 2016

Does nodenv work if you do have a v prefix? (does rvm support the v in .ruby-version?)

@koenpunt
Copy link
Contributor

koenpunt commented Dec 22, 2016

My assumption was it wouldn't work with the v prefix, but it does:

$ cat .node-version
v5.12.0
$ nodenv version
5.12.0 (set by /Users/koenpunt/.../.node-version)

rvm I don't know, but rbenv does, as is about the same as nodenv (nodenv is a port of rbenv)

@ljharb
Copy link
Member

ljharb commented Dec 22, 2016

That's encouraging - it means we could support v1.2.3 or 1.2.3. I'm hesitant to include the "iojs-" prefix, though, since there's no overlap with node - unless every other node version management tool supported it too.

Either way I've filed nodejs/version-management#13, and I think this issue should be blocked on that.

@philsturgeon
Copy link

I just swung by to leave an issue and see if there was any interest in this, but looks like there is!

RVM and rbenv both have their own files and formats but both agree on .ruby-version, and it would be lovely if nvm and nodenv could agree on a common file too, even if nothing changes by default.

Here's how RVM load the file:

.rvmrc - shell script allowing full customization of the environment,
.versions.conf - key=value configuration file
.ruby-version - single line ruby-version only
Gemfile - comment: #ruby=1.9.3 and directive: ruby "1.9.3"

So, we could very easily add another function to check for .node-version if there is no .nvmrc, agreed?

@philsturgeon
Copy link

Here you go! #1625

@ljharb
Copy link
Member

ljharb commented Sep 29, 2022

Nope, I don't typically commit to timelines on releases, let alone on making decisions :-)

The best way to help is to help take things off my plate - for nvm, the main blocker right now is converting travis tests to use Github Actions.

vipranarayan14 added a commit to vipranarayan14/samsaadhanii-concordance that referenced this issue Nov 22, 2022
What else?
Add '.nvmrc' also since nvm doesn't respect '.node-version' yet.
Ref: nvm-sh/nvm#794
@sospedra

This comment was marked as abuse.

@ljharb

This comment was marked as resolved.

@Ajedi32
Copy link

Ajedi32 commented Jan 16, 2023

Snark or no it's a fair point. It seems pretty clear .node-version is now a de-facto standard, if not a formal one, and NVM is the only notable holdout I can think of. @shadowspawn's node-version-usage repo linked above in several places lays out the case very comprehensively. There are plenty of actual W3C standards out there with far worse adoption than that.

All this has already been said before though; there's little point in repeating it ad infinitum. Upvote and move on.

robhogan added a commit to robhogan/react-native that referenced this issue Feb 18, 2023
Summary:
IMO, there's no value in having `.node-version` files either in the repository or the template.

I don't believe it's standard practice, the support from tooling is patchy (at least `nvm` [ignores it](nvm-sh/nvm#794), and Node is often used without a version manager), and it's unnecessarily restrictive when it is actually enforced. In every other case, it's potentially misleading noise.

Libraries should use `package.json#engines` to specify their Node JS compatibility ranges, as indeed `react-native` [already does](https://github.com/facebook/react-native/blob/1629b9f0a11f42ff12c6dd06a20afb80067e4958/package.json#L10). React Native users may wish to add one to their own projects according to their own setup or team, but we shouldn't confuse the issue by including an arbitrary one in the template.

Changelog:
[General][Removed] Remove `.node_version` from app template.

Differential Revision: D43421085

fbshipit-source-id: 37558ef3aee6479b40746cccf83beb1577473786
facebook-github-bot pushed a commit to facebook/react-native that referenced this issue Feb 20, 2023
Summary:
Pull Request resolved: #36208

IMO, there's no value in having `.node-version` files either in the repository or the template.

I don't believe it's standard practice, the support from tooling is patchy (at least `nvm` [ignores it](nvm-sh/nvm#794), and Node is often used without a version manager), and it's unnecessarily restrictive when it is actually enforced. In every other case, it's potentially misleading noise.

Libraries should use `package.json#engines` to specify their Node JS compatibility ranges, as indeed `react-native` [already does](https://github.com/facebook/react-native/blob/1629b9f0a11f42ff12c6dd06a20afb80067e4958/package.json#L10). React Native users may wish to add one to their own projects according to their own setup or team, but we shouldn't confuse the issue by including an arbitrary one in the template.

Changelog:
[General][Removed] Remove `.node_version` from app template.

Reviewed By: jacdebug, blakef

Differential Revision: D43421085

fbshipit-source-id: 37a9b0fb7701f06fffb867dbc7ecac479b4d9c95
@childrentime
Copy link

Can anyone write a shell script to automatically load a.node-version file like a.nvmrc file in nvm readme?

OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this issue May 22, 2023
Summary:
Pull Request resolved: facebook#36208

IMO, there's no value in having `.node-version` files either in the repository or the template.

I don't believe it's standard practice, the support from tooling is patchy (at least `nvm` [ignores it](nvm-sh/nvm#794), and Node is often used without a version manager), and it's unnecessarily restrictive when it is actually enforced. In every other case, it's potentially misleading noise.

Libraries should use `package.json#engines` to specify their Node JS compatibility ranges, as indeed `react-native` [already does](https://github.com/facebook/react-native/blob/1629b9f0a11f42ff12c6dd06a20afb80067e4958/package.json#L10). React Native users may wish to add one to their own projects according to their own setup or team, but we shouldn't confuse the issue by including an arbitrary one in the template.

Changelog:
[General][Removed] Remove `.node_version` from app template.

Reviewed By: jacdebug, blakef

Differential Revision: D43421085

fbshipit-source-id: 37a9b0fb7701f06fffb867dbc7ecac479b4d9c95
@bartekpacia

This comment was marked as off-topic.

@ljharb

This comment was marked as off-topic.

@mostlylikeable
Copy link

Somehow both n and fnm are able to support both .nvmrc and .node-version files. I would love to not need to create both files, when using any of the many other tools that recognize .node-version. This seems like such an inconsequential thing, and absolutely improves the nvm user's experience, that it's pretty surprising to me that this discussion has been ongoing for almost 9 years. Whether there are ongoing discussions around what standards .node-version should take or not, it's already become a defacto standard for many libraries.

@sebastiancarlos
Copy link

sebastiancarlos commented May 20, 2024

Add this to your .bashrc after your nvm configuration, and then run nvm-use when there's a '.node-version' file in your folder:

nvm-use() {
  # Print usage on -h or --help
  if [[ "$#" -eq 1 && ("$1" == "-h" || "$1" == "--help") ]]; then
    echo "Usage: nvm-use [nvm use options]"
    echo ""
    echo "- This function will look for a .node-version file in the current directory,"
    echo "  and run 'nvm use' with the version specified in that file."
    echo "- If no .node-version file is found, it will run 'nvm use' with"
    echo "  the arguments passed to this function."
    echo "- Note: This function might no longer be needed when this issue is solved:"
    echo "        https://github.com/nvm-sh/nvm/issues/794"
    echo ""
    echo "Options:"
    echo "  -h, --help    Show this help message and exit."
    return 0
  fi

  # Check for .node-version file and use its version if available
  if [[ $# -eq 0 && -f .node-version ]]; then
    local node_version
    node_version=$(<.node-version)
    node_version="${node_version//v/}" # Optionally remove 'v' prefix
    nvm use "$node_version"
  else
    echo "No .node-version file found. Falling back to 'nvm use' with default arguments."
    nvm use "$@"
  fi
}

@Qunapi
Copy link

Qunapi commented Jun 4, 2024

Looks like every other tool supports simple .node-version except nvm
https://github.com/shadowspawn/node-version-usage?tab=readme-ov-file#compatibility-testing
Is the lack of specification the only reason?
There were good examples like JSON or markdown mentioned. Typescript also doesn't have active specification and still, it's wildly used
If everyone else agrees to the format, who is NVM waiting for?

@robcresswell

This comment was marked as off-topic.

@mcandre

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature requests I want a new feature in nvm!
Projects
None yet
Development

Successfully merging a pull request may close this issue.