Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Allow frameworks to specify the minimum Node.js version #288

Open
@ehmicky

Description

@ehmicky

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: featurecode contributing to the implementation of a feature and/or user facing functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions