Skip to content

Commit 4220a3b

Browse files
committed
build(many): resolve .js specifiers to TypeScript source in webpack
The explicit .js relative-import extensions added for native ESM must still resolve when webpack bundles the .ts/.tsx source directly (Cypress component tests and the docs app). Add resolve.extensionAlias mapping .js->.ts/.tsx to the Cypress and ui-webpack-config configs so the source prep does not break those builds. No transpiler change.
1 parent e287fd4 commit 4220a3b

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

cypress/webpack.config.cjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ module.exports = {
7878
mode: 'development',
7979
resolve: {
8080
extensions: ['.ts', '.tsx', '.js'],
81+
// Source carries explicit `.js` extensions on relative imports (added for
82+
// native-ESM library output). When bundling `.ts`/`.tsx` source directly,
83+
// map a `.js` specifier back to its TypeScript source.
84+
extensionAlias: {
85+
'.js': ['.ts', '.tsx', '.js'],
86+
'.jsx': ['.tsx', '.jsx'],
87+
'.mjs': ['.mts', '.mjs']
88+
},
8189
alias: getWorkspaceAliases(),
8290
fallback: {
8391
fs: false,

packages/ui-webpack-config/config/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,16 @@ const config = {
4949
path: false,
5050
process: false // needed for Sinon 12+
5151
},
52-
extensions: ['.ts', '.tsx', '.js', '.json']
52+
extensions: ['.ts', '.tsx', '.js', '.json'],
53+
// Source now carries explicit `.js` extensions on relative imports (added
54+
// for native-ESM library output). When bundling the `.ts`/`.tsx` source
55+
// directly, map a `.js` specifier back to its TypeScript source so webpack
56+
// can resolve e.g. `import '../globals.js'` to `globals.ts`.
57+
extensionAlias: {
58+
'.js': ['.ts', '.tsx', '.js'],
59+
'.jsx': ['.tsx', '.jsx'],
60+
'.mjs': ['.mts', '.mjs']
61+
}
5362
}
5463
}
5564

0 commit comments

Comments
 (0)