Skip to content

Commit 6d95b6f

Browse files
committed
fix compilation
1 parent 084dfc2 commit 6d95b6f

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

packages/next/src/build/webpack-config.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,16 @@ const babelIncludeRegexes: RegExp[] = [
110110
/[\\/](strip-ansi|ansi-regex|styled-jsx)[\\/]/,
111111
]
112112

113-
const preCompileReactRegex =
114-
/next[\\/]dist[\\/]compiled[\\/](react|react-dom|react-server-dom-webpack)(-experimental)?($|[\\/])/
113+
const browserNonTranspileModules = [
114+
// Transpiling `process/browser` will trigger babel compilation error due to value replacement.
115+
// TypeError: Property left of AssignmentExpression expected node to be of a type ["LVal"] but instead got "BooleanLiteral"
116+
// e.g. `process.browser = true` will become `true = true`.
117+
/[\\/]node_modules[\\/]process[\\/]browser/,
118+
// Exclude precompiled react packages from browser compilation due to SWC helper insertion (#61791),
119+
// We fixed the issue but it's safer to exclude them from compilation since they don't need to be re-compiled.
120+
/[\\/]next[\\/]dist[\\/]compiled[\\/](react|react-dom|react-server-dom-webpack)(-experimental)?($|[\\/])/,
121+
]
122+
const precompileRegex = /[\\/]next[\\/]dist[\\/]compiled[\\/]/
115123

116124
const asyncStoragesRegex =
117125
/next[\\/]dist[\\/](esm[\\/])?client[\\/]components[\\/](static-generation-async-storage|action-async-storage|request-async-storage)/
@@ -1423,7 +1431,12 @@ export default async function getBaseWebpackConfig(
14231431
? [
14241432
{
14251433
test: codeCondition.test,
1426-
exclude: [codeCondition.exclude, transpilePackagesRegex],
1434+
exclude: [
1435+
// exclude unchanged modules from react-refresh
1436+
codeCondition.exclude,
1437+
transpilePackagesRegex,
1438+
precompileRegex,
1439+
],
14271440
issuerLayer: WEBPACK_LAYERS.appPagesBrowser,
14281441
use: reactRefreshLoaders,
14291442
resolve: {
@@ -1471,7 +1484,8 @@ export default async function getBaseWebpackConfig(
14711484
{
14721485
test: codeCondition.test,
14731486
issuerLayer: WEBPACK_LAYERS.appPagesBrowser,
1474-
exclude: preCompileReactRegex,
1487+
// Exclude the transpilation of the app layer due to compilation issues
1488+
exclude: browserNonTranspileModules,
14751489
use: appBrowserLayerLoaders,
14761490
resolve: {
14771491
mainFields: getMainField(compilerType, true),
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"presets": ["next/babel"],
33
"plugins": []
4-
}
4+
}

0 commit comments

Comments
 (0)