Unverified Commit 3ceab0e7 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

fix: specify supported nodejs version range (#72087)

### Why?

- Next.js uses
[AsyncLocalStorage.snapshot](https://github.com/vercel/next.js/blob/c32e2802097c03fd9f95b1dae228d6e0257569c0/packages/next/src/server/app-render/async-local-storage.ts#L60)
function.
- `AsyncLocalStorage.snapshot` [was added
in](https://nodejs.org/api/async_context.html#static-method-asynclocalstoragesnapshot)
Node.js `19.8.0`, `18.16.0`.
- However, the supported Node.js version range was `>= 18.18.0`.
- Which allowed Node.js `< 19.8.0` to be used, and causing an error:


![image](https://github.com/user-attachments/assets/c76b9ce2-c9e1-46c6-a472-d5268de76ff9)
> Image Source: https://x.com/smakosh/status/1851565997804667253

### How?

Modified the version range as `"^18.18.0 || ^19.8.0 || >= 20.0.0"`.
Confirmed that >= 20 are fully compatible so far.

### Things to Consider

Should we limit the upper to prevent deprecated/breaking changes?
If so, what would be the suitable upper-limit version?
parent ff41ad69
......@@ -344,6 +344,6 @@
"vercel"
],
"engines": {
"node": ">=18.18.0"
"node": "^18.18.0 || ^19.8.0 || >= 20.0.0"
}
}
......@@ -22,10 +22,13 @@ import type { NextDevOptions } from '../cli/next-dev.js'
import type { NextBuildOptions } from '../cli/next-build.js'
if (
semver.lt(process.versions.node, process.env.__NEXT_REQUIRED_NODE_VERSION!)
!semver.satisfies(
process.versions.node,
process.env.__NEXT_REQUIRED_NODE_VERSION_RANGE!
)
) {
console.error(
`You are using Node.js ${process.versions.node}. For Next.js, Node.js version >= v${process.env.__NEXT_REQUIRED_NODE_VERSION} is required.`
`You are using Node.js ${process.versions.node}. For Next.js, Node.js version "${process.env.__NEXT_REQUIRED_NODE_VERSION_RANGE}" is required.`
)
process.exit(1)
}
......
......@@ -184,8 +184,8 @@ function setNextVersion(code) {
`"${require('./package.json').version}"`
)
.replace(
/process\.env\.__NEXT_REQUIRED_NODE_VERSION/g,
`"${require('./package.json').engines.node.replace('>=', '')}"`
/process\.env\.__NEXT_REQUIRED_NODE_VERSION_RANGE/g,
`"${require('./package.json').engines.node}"`
)
.replace(
/process\.env\.REQUIRED_APP_REACT_VERSION/,
......
......@@ -115,15 +115,17 @@ describe('next/swc', () => {
})
describe('private env replacement', () => {
it('__NEXT_REQUIRED_NODE_VERSION is replaced', async () => {
it('__NEXT_REQUIRED_NODE_VERSION_RANGE is replaced', async () => {
const pkgDir = path.dirname(require.resolve('next/package.json'))
const nextEntryContent = await fsp.readFile(
path.join(pkgDir, 'dist/bin/next'),
'utf8'
)
expect(nextEntryContent).not.toContain('__NEXT_REQUIRED_NODE_VERSION')
expect(nextEntryContent).not.toContain(
'__NEXT_REQUIRED_NODE_VERSION_RANGE'
)
expect(nextEntryContent).toMatch(
/For Next.js, Node.js version >= v\$\{"\d+\.\d+\.\d*"\}/
/For Next.js, Node.js version "\$\{"\^\d+\.\d+\.\d* \|\| \^\d+\.\d+\.\d* \|\| >= \d+\.\d+\.\d*"\}" is required./
)
})
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment