diff --git a/.changeset/nasty-kids-tickle.md b/.changeset/nasty-kids-tickle.md new file mode 100644 index 000000000..2b95f9ff4 --- /dev/null +++ b/.changeset/nasty-kids-tickle.md @@ -0,0 +1,5 @@ +--- +'@cloudflare/next-on-pages': patch +--- + +Fix the Webpack chunk deduplication when Sentry is used, as it changes the AST node structure for Webpack chunks. diff --git a/packages/next-on-pages/src/buildApplication/processVercelFunctions/ast.ts b/packages/next-on-pages/src/buildApplication/processVercelFunctions/ast.ts index 35a4651a5..f16584fe4 100644 --- a/packages/next-on-pages/src/buildApplication/processVercelFunctions/ast.ts +++ b/packages/next-on-pages/src/buildApplication/processVercelFunctions/ast.ts @@ -269,32 +269,39 @@ function extractManifest( function extractWebpack( statement: AST.StatementKind, ): RawIdentifier<'webpack'>[] { + if (statement.type !== 'ExpressionStatement') return []; + + const expr = + statement.expression.type === 'SequenceExpression' + ? statement.expression.expressions.find( + expr => expr.type === 'CallExpression', + ) + : statement.expression; + if ( - statement.type !== 'ExpressionStatement' || - statement.expression.type !== 'CallExpression' || - statement.expression.callee.type !== 'MemberExpression' || - statement.expression.callee.property.type !== 'Identifier' || - statement.expression.callee.property.name !== 'push' || - statement.expression.callee.object.type !== 'AssignmentExpression' || - !isSelfWebpackChunk_N_E(statement.expression.callee.object.left) || - statement.expression.callee.object.right.type !== 'LogicalExpression' || - !isSelfWebpackChunk_N_E(statement.expression.callee.object.right.left) || - statement.expression.callee.object.right.right.type !== 'ArrayExpression' || - statement.expression.callee.object.right.right.elements.length !== 0 || - statement.expression.arguments[0]?.type !== 'ArrayExpression' || - statement.expression.arguments[0].elements[1]?.type !== 'ObjectExpression' + expr?.type !== 'CallExpression' || + expr.callee.type !== 'MemberExpression' || + expr.callee.property.type !== 'Identifier' || + expr.callee.property.name !== 'push' || + expr.callee.object.type !== 'AssignmentExpression' || + !isSelfWebpackChunk_N_E(expr.callee.object.left) || + expr.callee.object.right.type !== 'LogicalExpression' || + !isSelfWebpackChunk_N_E(expr.callee.object.right.left) || + expr.callee.object.right.right.type !== 'ArrayExpression' || + expr.callee.object.right.right.elements.length !== 0 || + expr.arguments[0]?.type !== 'ArrayExpression' || + expr.arguments[0].elements[1]?.type !== 'ObjectExpression' ) { return []; } - const properties = - statement.expression.arguments[0].elements[1].properties.filter( - p => - p.type === 'Property' && - p.key.type === 'Literal' && - typeof p.key.value === 'number' && - p.value.type === 'ArrowFunctionExpression', - ) as AST.PropertyKind[]; + const properties = expr.arguments[0].elements[1].properties.filter( + p => + p.type === 'Property' && + p.key.type === 'Literal' && + typeof p.key.value === 'number' && + p.value.type === 'ArrowFunctionExpression', + ) as AST.PropertyKind[]; return properties.map(chunk => ({ type: 'webpack',