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

Not accurate node engine version range - it should be ^14.18.0 || >=16.0.0 #5575

Closed
pieh opened this issue Mar 17, 2023 · 0 comments · Fixed by #5602
Closed

Not accurate node engine version range - it should be ^14.18.0 || >=16.0.0 #5575

pieh opened this issue Mar 17, 2023 · 0 comments · Fixed by #5602
Labels
type: bug code to address defects in shipped code

Comments

@pieh
Copy link
Contributor

pieh commented Mar 17, 2023

Describe the bug

In package.json there is following metadata:

  "engines": {
    "node": "^14.16.0 || >=16.0.0"
  },

But package actually fails to install on Node 14.16 when running postinstall script:

Error: Cannot find module 'node:fs'
Require stack:
- /Users/misiek/dev/netlify-cli/node_modules/@fastify/send/lib/SendStream.js
- /Users/misiek/dev/netlify-cli/node_modules/@fastify/send/index.js
- /Users/misiek/dev/netlify-cli/node_modules/@fastify/static/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/Users/misiek/dev/netlify-cli/node_modules/@fastify/send/lib/SendStream.js:13:12)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/misiek/dev/netlify-cli/node_modules/@fastify/send/lib/SendStream.js',
    '/Users/misiek/dev/netlify-cli/node_modules/@fastify/send/index.js',
    '/Users/misiek/dev/netlify-cli/node_modules/@fastify/static/index.js'
  ]

This is because support for require('node:X') was only added in Node 14.18 ( expand history in https://nodejs.org/api/esm.html#node-imports for reference ).

This is the case for current and previous major of netlify-cli.

I think there is no non-hacky way to fix this to make it work with reported minimum node version + the fact that it wasn't working on that min version it might make sense to adjust package.json to say Node@14.18 - which technically is a breaking change, but that is factual state of supported node version, just wrongly reported.

The hacky way is something like this https://github.com/gatsbyjs/gatsby/blob/master/e2e-tests/production-runtime/polyfill-node-protocol-imports.js but we are only doing this for e2e tests, not actually releasing that to npm and I would not suggest to adopt something like that for package that is released to npm.

This issue came up in netlify/gatsby-plugin-netlify#232

Steps to reproduce

Easiest is to go inside netlify-cli repo clone dir and run following

nvm install 14.16
npm run postinstall

Configuration

No response

Environment

  System:
    OS: macOS 13.2.1
    CPU: (12) x64 Apple M2 Pro
    Memory: 1.22 GB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 14.16.0 - ~/.nvm/versions/node/v14.16.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.14.0/bin/yarn
    npm: 6.14.11 - ~/.nvm/versions/node/v14.16.0/bin/npm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant