fix: Add extensionAlias for ESM TS to webpack-batteries-included#31994
Conversation
|
6cfaa7f to
f5bfd99
Compare
AtofStryker
left a comment
There was a problem hiding this comment.
Hi @mdmower-csnw.
Thank you for opening a PR. Are you able to add some type of test, preferably a system-test that showcases how add resolveAlias helps resolve the extensions of a given file?
@AtofStryker - Test added in 43e5923. I also fixed an oversight on my part to load |
AtofStryker
left a comment
There was a problem hiding this comment.
Looks good to me. Thank you @mdmower-csnw !
For TypeScript ESM projects that use module resolution requiring file extensions, `.js` extension must be used for `.ts` imports. Take advantage of `resolve.extensionAlias` to resolve these imports. Fixes cypress-io#26827 Fixes cypress-io#28805
…-included - Update typescript regex to allow .mts files - Add ESM import tests
3f2986a to
45a4fc6
Compare
|
I'm not sure whether my input is needed on the cursor bot suggestions; I'll give my 2cents.
Module resolution name possibilities:
In summary, adding
This assignment was chosen after I verified webpackOptions.resolve.extensionAlias = {
...webpackOptions.resolve.extensionAlias,
'.js': ['.ts', '.js'],
'.mjs': ['.mts', '.mjs'],
} |
@mdmower-csnw I think the only thing that I really took away from the suggestions was that we want to keep webpackOptions.resolve.extensionAlias = webpackOptions.resolve.extensionAlias || { '.js': ['.ts', '.js'], '.mjs': ['.mts', '.mjs'] }This should be sufficient |
There was a problem hiding this comment.
Bug: TypeScript Module Resolution Fails
The commit introduces two issues affecting TypeScript module resolution:
resolve.extensionAliasmerging: ThewebpackOptions.resolve.extensionAliasassignment uses the logical OR (||) operator. This prevents the new TypeScript aliases (.js->.ts,.mjs->.mts) from merging with existing user configurations, breaking TypeScript ESM import resolution when users have their ownextensionAliassettings.resolve.extensionsincompleteness: Although thetypescriptExtensionRegexandts-loaderare updated to process.mtsand.mtsxfiles, these extensions are not added towebpackOptions.resolve.extensions. This prevents webpack from resolving direct or extensionless imports of.mtsand.mtsxfiles.
npm/webpack-batteries-included-preprocessor/index.js#L64-L66
cypress/npm/webpack-batteries-included-preprocessor/index.js
Lines 64 to 66 in b16d9c6
Was this report helpful? Give feedback by reacting with 👍 or 👎
|
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
For TypeScript ESM projects that use module resolution requiring file extensions,
.js/.mjsextension must be used for.ts/.mtsimports..mtsfiles withts-loader..mtstext fixture and ESM import test.Closes #26827
Closes #28805