Skip to content

Commit

Permalink
fix compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Feb 8, 2024
1 parent 084dfc2 commit 6d95b6f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
22 changes: 18 additions & 4 deletions packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,16 @@ const babelIncludeRegexes: RegExp[] = [
/[\\/](strip-ansi|ansi-regex|styled-jsx)[\\/]/,
]

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

const asyncStoragesRegex =
/next[\\/]dist[\\/](esm[\\/])?client[\\/]components[\\/](static-generation-async-storage|action-async-storage|request-async-storage)/
Expand Down Expand Up @@ -1423,7 +1431,12 @@ export default async function getBaseWebpackConfig(
? [
{
test: codeCondition.test,
exclude: [codeCondition.exclude, transpilePackagesRegex],
exclude: [
// exclude unchanged modules from react-refresh
codeCondition.exclude,
transpilePackagesRegex,
precompileRegex,
],
issuerLayer: WEBPACK_LAYERS.appPagesBrowser,
use: reactRefreshLoaders,
resolve: {
Expand Down Expand Up @@ -1471,7 +1484,8 @@ export default async function getBaseWebpackConfig(
{
test: codeCondition.test,
issuerLayer: WEBPACK_LAYERS.appPagesBrowser,
exclude: preCompileReactRegex,
// Exclude the transpilation of the app layer due to compilation issues
exclude: browserNonTranspileModules,
use: appBrowserLayerLoaders,
resolve: {
mainFields: getMainField(compilerType, true),
Expand Down
2 changes: 1 addition & 1 deletion test/integration/babel-next-image/.babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"presets": ["next/babel"],
"plugins": []
}
}

0 comments on commit 6d95b6f

Please sign in to comment.