Skip to content

Commit

Permalink
Do not warn during build for supported modules in the Edge runtime (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
unstubbable authored Jan 10, 2025
1 parent 6c52257 commit 5bd025d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 28 deletions.
6 changes: 5 additions & 1 deletion packages/next/src/build/webpack/plugins/middleware-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,11 @@ function getCodeAnalyzer(params: {
sourceContent: source.toString(),
})

if (!dev && isNodeJsModule(importedModule)) {
if (
!dev &&
isNodeJsModule(importedModule) &&
!SUPPORTED_NATIVE_MODULES.includes(importedModule)
) {
compilation.warnings.push(
buildWebpackError({
message: `A Node.js module is loaded ('${importedModule}' at line ${node.loc.start.line}) which is not supported in the Edge Runtime.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { nextTestSetup } from 'e2e-utils'

describe('edge runtime node compatibility', () => {
const { next } = nextTestSetup({
const { next, isNextStart } = nextTestSetup({
files: __dirname,
})

Expand Down Expand Up @@ -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./
)
})
}
})
10 changes: 10 additions & 0 deletions test/e2e/app-dir/edge-runtime-node-compatibility/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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()
}
26 changes: 0 additions & 26 deletions test/e2e/app-dir/edge-runtime-node-compatibility/tsconfig.json

This file was deleted.

0 comments on commit 5bd025d

Please sign in to comment.