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

Proposal: Add a function to automatically switch node version according to the project root configuration file. #42194

Closed
kiccer opened this issue Mar 3, 2022 · 12 comments
Labels
feature request Issues that request new features to be added to Node.js.

Comments

@kiccer
Copy link

kiccer commented Mar 3, 2022

What is the problem this feature will solve?

I am using Node on windows 10 and I maintain several projects with different versions of Node. I have installed NVM to control the Node version, which is convenient but not enough. It would be nice if Node versions could be switched automatically according to the project!

What is the feature you are proposing to solve the problem?

I have an idea, which I don't know if it's possible to implement, and it goes like this

When a program calls Node, this shell will first determine whether the program is in the root directory with a configuration file specifying the Node version, and if so, the corresponding version of Node will be used, otherwise the globally specified Node version will be used.

I guess this feature will help a lot of people to improve their work efficiency, and I look forward to getting attention for this requirement, tks.

What alternatives have you considered?

No response

@kiccer kiccer added the feature request Issues that request new features to be added to Node.js. label Mar 3, 2022
@Ayase-252
Copy link
Member

I think it is better to implemented in a node version manager like nvm. One node would not know where other nodes are installed.

@WillianAgostini
Copy link

I agree, this will be very helpful. I work too with many versions of node with different projects.
How about moving this feature to https://github.com/nvm-sh/nvm repository.

@Trott
Copy link
Member

Trott commented Mar 3, 2022

I agree, this will be very helpful. I work too with many versions of node with different projects. How about moving this feature to https://github.com/nvm-sh/nvm repository.

@nodejs/version-management

@Trott
Copy link
Member

Trott commented Mar 3, 2022

I've tried transferring this to the version-management repo twice now and it keeps getting stuck. I've waited a while and will try one more time, but if it doesn't work, I'll leave it here in the node repo....

@ljharb
Copy link
Member

ljharb commented Mar 3, 2022

nodejs/version-management#28 does seem to exist; maybe GitHub’s having trouble.

@Trott
Copy link
Member

Trott commented Mar 3, 2022

nodejs/version-management#28 does seem to exist; maybe GitHub’s having trouble.

Nah, that's what happens each time. It gets as far as the first comment and then stops, seemingly forever. This will have higher visibility in this repo anyway, so let's just have the conversation here, I guess. (EDIT: Or somehow manually transfer it but quoting everything relevant in a comment. But I think leaving it here is fine.)

@Mesteery
Copy link
Contributor

Mesteery commented Mar 3, 2022

There is Volta that can do this, if I understand your issue correctly.

https://docs.volta.sh/guide/understanding#managing-your-project

@ljharb
Copy link
Member

ljharb commented Mar 3, 2022

Either way, I think this should be closed; there's a lot of challenges and prerequisites to node doing version management, and "a configuration file" is also difficult because there's not yet any specification for intersection semantics for "how to describe a version". https://github.com/nodejs/version-management is the place to discuss this, and there's existing issues doing so for those interested to read.

@coreybutler
Copy link
Member

I agree with @ljharb - this issue should be closed in favor of discussion on more appropriate forums.

The original post specifically calls out NVM for Windows (nvm-windows), so anyone coming across this from Google who wants this functionality on Windows is welcome to discuss it at https://github.com/coreybutler/nvm-windows (discussion board is best). There are many nuances to contend with on Windows.

@Trott
Copy link
Member

Trott commented Mar 3, 2022

OK, I'm going to close this but also encourage the original poster and anyone else interested to find existing issues or open new issues in https://github.com/nodejs/version-management to discuss this further. Thanks, everyone!

@Trott Trott closed this as completed Mar 3, 2022
@shadowspawn
Copy link
Member

Related links

Discussion on a standard location for where node versions are installed:

Discussion on a standard for specifying the node "version":

Applications in the wild which use .node-version to switch node version:

@jasonkarns
Copy link
Member

To the OP's original request, this is exactly what nodenv does already.

Invocations of node and node's executables (via global node_modules) are routed to the desired node version by the presence of NODENV_VERSION, .node-version file in hierarchy of CWD, and finally a default "global" node version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js.
Projects
None yet
Development

No branches or pull requests

9 participants