Skip to content

Commit

Permalink
Fix esm module import warning for middleware loader (#51014)
Browse files Browse the repository at this point in the history
We need to spread the module into an object instead of access the module exports that could not exist, to avoid triggering the warning. Fix the bad loader change introduced in #50548 

```
Attempted import error: './middleware.js' does not contain a default export (imported as '
mod').
- info Using locally built binary of @next/swc
- warn You are using an experimental edge runtime, the API might change.
- wait compiling...
- warn ../../../../packages/next/dist/build/webpack/loaders/next-middleware-loader.js?abso
lutePagePath=%2FUsers%2Fhuozhi%2Fworkspace%2Fnext.js%2Ftest%2Fe2e%2Fapp-dir%2Fapp%2Fmiddle
ware.js&page=%2Fmiddleware&rootDir=%2FUsers%2Fhuozhi%2Fworkspace%2Fnext.js%2Ftest%2Fe2e%2F
app-dir%2Fapp&matchers=!
Attempted import error: './middleware.js' does not contain a default export (imported as '
mod').
- wait compiling...
```
  • Loading branch information
huozhi committed Jun 9, 2023
1 parent 9800eaf commit 2a2890c
Showing 1 changed file with 2 additions and 1 deletion.
Expand Up @@ -42,8 +42,9 @@ export default function middlewareLoader(this: any) {
return `
import 'next/dist/esm/server/web/globals'
import { adapter } from 'next/dist/esm/server/web/adapter'
import * as mod from ${stringifiedPagePath}
import * as _mod from ${stringifiedPagePath}
const mod = { ..._mod }
const handler = mod.middleware || mod.default
if (typeof handler !== 'function') {
Expand Down

0 comments on commit 2a2890c

Please sign in to comment.