@@ -74,44 +74,28 @@ export default [
7474 ] ,
7575 plugins : [
7676 {
77- name : 'sentry-fix-rolldown-generated-identifiers ' ,
77+ name : 'sentry-fix-missing-serverComponentModule-import ' ,
7878 renderChunk ( code , chunk ) {
79- // Rolldown generates import identifiers like `__SENTRY_WRAPPING_TARGET_FILE___default` for default imports
80- // from our placeholder modules. When the wrapping loader later replaces `__SENTRY_WRAPPING_TARGET_FILE__`
81- // with `__SENTRY_WRAPPING_TARGET_FILE__.cjs`, this creates invalid syntax like
82- // `__SENTRY_WRAPPING_TARGET_FILE__.cjs_default`, where `.cjs` breaks the identifier.
83- // We fix this by replacing the problematic identifier pattern with a safe one that uses a different
84- // separator that won't be confused with property access when the placeholder is replaced.
85- let fixedCode = code
86- . replace (
87- / _ _ S E N T R Y _ W R A P P I N G _ T A R G E T _ F I L E _ _ _ d e f a u l t / g,
88- '__SENTRY_WRAPPING_TARGET_FILE_PLACEHOLDER_DEFAULT__' ,
89- )
90- . replace ( / _ _ S E N T R Y _ C O N F I G _ I M P O R T _ P A T H _ _ _ d e f a u l t / g, '__SENTRY_CONFIG_IMPORT_PATH_PLACEHOLDER_DEFAULT__' )
91- . replace (
92- / _ _ S E N T R Y _ N E X T J S _ R E Q U E S T _ A S Y N C _ S T O R A G E _ S H I M _ _ _ d e f a u l t / g,
93- '__SENTRY_NEXTJS_REQUEST_ASYNC_STORAGE_SHIM_PLACEHOLDER_DEFAULT__' ,
94- ) ;
95-
9679 // Rolldown has a bug where it removes namespace imports for external modules even when they're still
9780 // referenced in the code (specifically when there's a `declare const` with the same name in the source).
9881 // We need to add back the missing import for serverComponentModule in the serverComponentWrapperTemplate.
9982 if (
10083 chunk . facadeModuleId ?. includes ( 'serverComponentWrapperTemplate' ) &&
101- fixedCode . includes ( 'serverComponentModule' ) &&
102- ! fixedCode . includes ( 'import * as serverComponentModule' )
84+ code . includes ( 'serverComponentModule' ) &&
85+ ! code . includes ( 'import * as serverComponentModule' )
10386 ) {
10487 // Find the position after the last import statement to insert our missing import
105- const lastImportMatch = fixedCode . match ( / ^ i m p o r t [ ^ ; ] * ; / gm) ;
88+ const lastImportMatch = code . match ( / ^ i m p o r t [ ^ ; ] * ; / gm) ;
10689 if ( lastImportMatch ) {
10790 const lastImport = lastImportMatch [ lastImportMatch . length - 1 ] ;
108- const lastImportEnd = fixedCode . indexOf ( lastImport ) + lastImport . length ;
109- fixedCode = `${ fixedCode . slice ( 0 , lastImportEnd ) }
110- import * as serverComponentModule from "__SENTRY_WRAPPING_TARGET_FILE__";${ fixedCode . slice ( lastImportEnd ) } ` ;
91+ const lastImportEnd = code . indexOf ( lastImport ) + lastImport . length ;
92+ return {
93+ code : `${ code . slice ( 0 , lastImportEnd ) }
94+ import * as serverComponentModule from "__SENTRY_WRAPPING_TARGET_FILE__";${ code . slice ( lastImportEnd ) } ` ,
95+ } ;
11196 }
11297 }
113-
114- return { code : fixedCode } ;
98+ return null ;
11599 } ,
116100 } ,
117101 ] ,
0 commit comments