Skip to content

Commit f2666e8

Browse files
author
Tajudeen
committed
Fix React build: Keep chunk imports relative for ES module compatibility
- Fixed blank screen issue caused by invalid ES module specifiers - Chunk imports now use relative paths (../chunk-*.js) instead of absolute paths - Absolute paths starting with 'vs/' are not valid ES module specifiers - Other imports continue to use absolute paths for proper resolution
1 parent dcc0d1d commit f2666e8

File tree

1 file changed

+24
-19
lines changed
  • src/vs/workbench/contrib/cortexide/browser/react

1 file changed

+24
-19
lines changed

src/vs/workbench/contrib/cortexide/browser/react/build.js

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,21 @@ function fixImportPaths() {
183183
}
184184

185185
// Replace all relative imports with absolute paths
186-
// BUT keep chunk imports relative (they're part of the bundle)
186+
// BUT keep chunk imports relative (they're in the same directory structure and work with relative paths)
187187
const convertRelativeFromImport = (match, quote, dots, rest) => {
188-
if (rest.startsWith('./') || rest.startsWith('vs/') || rest.startsWith('chunk-')) {
188+
// Skip if already absolute (starts with vs/)
189+
if (rest.startsWith('vs/')) {
189190
return match;
190191
}
192+
// Keep chunk imports relative - they're in the same directory structure
193+
if (rest.startsWith('chunk-')) {
194+
return match; // Keep relative path
195+
}
196+
// Skip relative imports starting with ./
197+
if (rest.startsWith('./')) {
198+
return match;
199+
}
200+
// Convert other relative imports to absolute paths
191201
const resolved = resolveRelativeImport(`${dots}${rest}`);
192202
if (resolved !== `${dots}${rest}`) {
193203
return `from ${quote}${resolved}${quote}`;
@@ -203,9 +213,19 @@ function fixImportPaths() {
203213
content = content.replace(
204214
/import\s+(['"])((?:\.\.\/)+)([^'";\n]+)\1/g,
205215
(match, quote, dots, rest) => {
206-
if (rest.startsWith('./') || rest.startsWith('vs/') || rest.startsWith('chunk-')) {
216+
// Skip if already absolute (starts with vs/)
217+
if (rest.startsWith('vs/')) {
218+
return match;
219+
}
220+
// Keep chunk imports relative - they're in the same directory structure
221+
if (rest.startsWith('chunk-')) {
222+
return match; // Keep relative path
223+
}
224+
// Skip relative imports starting with ./
225+
if (rest.startsWith('./')) {
207226
return match;
208227
}
228+
// Convert other relative imports to absolute paths
209229
const resolved = resolveRelativeImport(`${dots}${rest}`);
210230
if (resolved !== `${dots}${rest}`) {
211231
return `import ${quote}${resolved}${quote}`;
@@ -214,22 +234,6 @@ function fixImportPaths() {
214234
}
215235
);
216236

217-
// Also fix any absolute chunk imports that were incorrectly converted
218-
// Convert them back to relative imports
219-
content = content.replace(
220-
/from\s+(['"])vs\/workbench\/contrib\/cortexide\/browser\/react\/out\/(chunk-[^'"]+)\1/g,
221-
(match, quote, chunkName) => {
222-
// Get the directory of the current file relative to react/out/
223-
const currentFileDir = path.dirname(fileRelPath);
224-
// Chunks are in react/out/, entry points are in react/out/subdir/
225-
if (currentFileDir === 'vs/workbench/contrib/cortexide/browser/react/out') {
226-
return `from ${quote}./${chunkName}${quote}`;
227-
}
228-
// If in a subdirectory (e.g., void-settings-tsx/), use relative path
229-
return `from ${quote}../${chunkName}${quote}`;
230-
}
231-
);
232-
233237
// Ensure browser-level modules always point to the browser directory
234238
content = content
235239
.replace(/vs\/workbench\/contrib\/cortexide\/actionIDs\.js/g, 'vs/workbench/contrib/cortexide/browser/actionIDs.js')
@@ -395,6 +399,7 @@ if (isWatch) {
395399
execSync('npx tsup', { stdio: 'inherit' });
396400

397401
// Fix import paths in bundled files
402+
// allow-any-unicode-next-line
398403
console.log('🔧 Fixing import paths...');
399404
fixImportPaths();
400405

0 commit comments

Comments
 (0)