question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow frameworks to specify the minimum Node.js version

See original GitHub issue

All 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 in package.json. This is also consistent with how npm and yarn behave during npm 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:open
  • Created 2 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
ascorbiccommented, Jun 7, 2021

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.

1reaction
ascorbiccommented, Nov 2, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I specify the required Node.js version in package.json?
Original Answer. engineStrict is now deprecated, so this will only give a warning. It's now down to the user to run npm config...
Read more >
Compatibility and requirements for the Node.js agent
The Node.js agent is compatible with the following operating systems: Linux; SmartOS; macOS 10.7 and higher; Windows Server 2008 and higher The following...
Read more >
Node.js Runtime Environment - App Engine - Google Cloud
Node.js version ... The Node.js runtime supports Node.js 18 (preview), Node.js 16, Node.js 14, Node.js 12, and Node.js 10. The runtime uses the...
Read more >
Setting up a Node development environment - MDN Web Docs
The Express development environment includes an installation of Nodejs, the npm package manager, and (optionally) the Express Application ...
Read more >
The Difference Between Node.js 10 LTS and Node.js 12 LTS
They allow to write an array of ArrayBufferView s to a file descriptor (Anas Aboureada) #25925, ... Added min/max protocol version options.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found