Unverified Commit c86062ac authored by Hendrik Liebau's avatar Hendrik Liebau Committed by GitHub

Prevent incompability with `'eval-source-map'` and `mangle: false` (#68688)

Setting the terser option `mangle` to `false` for dev server runtime
bundles as done in #68641 seems to be incompatible with
`'eval-source-map'`, i.e. when running `pnpm dev`. The combination
yields strange runtime errors when running an app with the node runtime.
E.g.:
```
 ⨯ TypeError: isValidElementType is not a function
    at renderToHTMLImpl (webpack://next/dist/src/server/render.tsx?e2d9:568:10)
    at render (webpack://next/dist/src/server/route-modules/pages/module.ts?84fd:125:12)
```
or
```
TypeError: Cannot read properties of undefined (reading 'contexts')
    at Object.<anonymous> (<snip>/packages/next/src/server/route-modules/pages/vendored/contexts/html-context.ts:1:59)
```
or
```
 ⨯ Error: Cannot find module 'next/dist/server/lib/trace/tracer'
Require stack:
- <snip>/packages/next/dist/compiled/next-server/app-page.runtime.dev.js
- <snip>/test/e2e/app-dir/app/.next/server/app/dashboard/page.js
```

Since using `'eval-source-map'` already fixes showing the original
names, we don't need to disable mangling in this case.

**How to reproduce on `canary`:**

- start `pnpm dev`
- start `pnpm next dev test/e2e/app-dir/app`
- open http://localhost:3000/client-component-route
- observe errors
parent 20e3b773
......@@ -173,7 +173,8 @@ module.exports = ({ dev, turbo, bundleType, experimental }) => {
format: {
preamble: '',
},
mangle: dev ? false : true,
mangle:
dev && !process.env.NEXT_SERVER_EVAL_SOURCE_MAPS ? false : true,
},
}),
],
......
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