Unverified Commit 5bd025d4 authored by Hendrik Liebau's avatar Hendrik Liebau Committed by GitHub

Do not warn during build for supported modules in the Edge runtime (#74752)

When using a Node.js module that is [supported in the Edge
runtime](https://vercel.com/docs/functions/runtimes/edge-runtime#compatible-node.js-modules),
we must not emit a warning during build.
parent 6c52257a
...@@ -511,7 +511,11 @@ function getCodeAnalyzer(params: { ...@@ -511,7 +511,11 @@ function getCodeAnalyzer(params: {
sourceContent: source.toString(), sourceContent: source.toString(),
}) })
if (!dev && isNodeJsModule(importedModule)) { if (
!dev &&
isNodeJsModule(importedModule) &&
!SUPPORTED_NATIVE_MODULES.includes(importedModule)
) {
compilation.warnings.push( compilation.warnings.push(
buildWebpackError({ buildWebpackError({
message: `A Node.js module is loaded ('${importedModule}' at line ${node.loc.start.line}) which is not supported in the Edge Runtime. message: `A Node.js module is loaded ('${importedModule}' at line ${node.loc.start.line}) which is not supported in the Edge Runtime.
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
describe('edge runtime node compatibility', () => { describe('edge runtime node compatibility', () => {
const { next } = nextTestSetup({ const { next, isNextStart } = nextTestSetup({
files: __dirname, files: __dirname,
}) })
...@@ -46,4 +46,12 @@ describe('edge runtime node compatibility', () => { ...@@ -46,4 +46,12 @@ describe('edge runtime node compatibility', () => {
]), ]),
}) })
}) })
if (isNextStart) {
it('does not warn when using supported node modules', () => {
expect(next.cliOutput).not.toMatch(
/A Node.js module is loaded \('async_hooks' at line \d+\) which is not supported in the Edge Runtime./
)
})
}
}) })
import { NextResponse, NextRequest } from 'next/server'
import { AsyncLocalStorage } from 'async_hooks'
const storage = new AsyncLocalStorage<{}>()
export async function middleware(request: NextRequest) {
storage.run({}, () => {})
return NextResponse.next()
}
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true,
"target": "ES2017"
},
"include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
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