Allow frameworks to specify the minimum Node.js version
See original GitHub issueAll Node.js-based frameworks have a specific minimum Node.js version.
At the moment, if a user runs a framework on Netlify with a Node.js version that’s too old, the framework will most likely fail at require()
-time with some cryptic error message due to some unsupported JavaScript feature or missing Node.js core method. Users might be confused and think this is a bug in Netlify.
Since we detect frameworks, we could use that knowledge to infer the minimum Node.js version. We could do this by adding a new nodeVersionRange
field to the frameworks declarations:
- The value would be a semver range like
^10 || >=12
or>=12.20.0
since some frameworks support Node.js version range that are more complex than just>=version
. - The minimal version can still be inferred (for example to use as a default Node.js version) using
node-semver
minVersion()
method.
We could use that information to either:
- Warn users when using the wrong Node.js version, for example by printing a message in the build logs.
- Choose the default Node.js version run in builds
I would personally favor only warning users and not overriding the Node.js version based on that information because:
- The logic to decide on the default Node.js version is already quite complicated as mentioned by @ingride
- Users might not expect that Node.js version unless documented, and documenting it clearly might be difficult if it’s framework-specific.
- When using multiple frameworks, their ranges might be in conflict. This could be fixed by using an intersection, but I am wondering whether that intersection might be empty in some cases.
- It is consistent with our current strategy for Build plugins. For Build plugins, we not only warn users but fail the build altogether when the Node.js version is incompatible. We do this based on the
engines.node
field inpackage.json
. This is also consistent with hownpm
andyarn
behave duringnpm install
(although one warns only while the other fails).
That being said, I could also see an argument being made that Netlify users might expect the platform to just use the right Node.js version so things “just work” with their chosen framework.
Note: this discussion was brought up due to Nuxt supporting only Node.js >=12.20.0
.
I would be very curious to learn more about what you all think about this idea, especially @ingride @JGAntunes @erezrokah @verythorough @lukeocodes @ascorbic. Thanks!
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (11 by maintainers)
Top GitHub Comments
That sounds like the simplest solution. I can’t think of a scenario where a new site wouldn’t work with LTS, but if there were I think it would be rare enough to say that they could set it manually.
I’ve highlighted this again internally, as I think this is a growing problem. As well as SvelteKit it now affects Gatsby and in some cases Next.js.