You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Inconsistency with TypeScript in Module Resolution with Fully-Specified ESM Imports #904
Fully-specified ES Module Imports (with the .js extension) do not resolve to the correct, matching .ts or .tsx files (as is the behavior of TypeScript and tsx, as per the TypeScript team here: microsoft/TypeScript#41887 (comment) )
babel-loader resolves modules the same as TypeScript and tsx do.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem along with a gist/jsbin of your webpack configuration.
Ideally ts-loader should respect resolve.extensions (better resolve.byDependency.typescript) and when you using import something from './foo.js' try to resolve ./foo.js as ./foo.tsx/./foo.ts and then other variants (i.e. ./foo.js and etc).
So I guess once this resolver plugin exists, if it won't be enabled automatically (which would be ideal), loaders who consume TS should verify that this resolver plugin is enabled.
Activity
nicolo-ribaudo commentedon Apr 28, 2021
babel-loaderdoesn't do any module resolution: it's just about compiling syntax.You could use a Babel plugin to rewrite import paths (for example, https://www.npmjs.com/package/babel-plugin-module-rewrite), but it really should be done by configuring webpack to use the resolution strategy you want.
karlhorky commentedon Apr 28, 2021
Yeah, that was my first impression as well - first of all, we started the investigation on the webpack end.
But in the end, users will configure
babel-loaderand expect that any valid ESM imports that work with TypeScript +tscwill also work there.As Alexander says below, webpack is currently working correctly, so this becomes a concern of the loaders, such as
ts-loader, which he will work on:webpack/webpack#13252 (comment)
More details from Alexander:
karlhorky commentedon Apr 29, 2021
Ah Sokra has now said it will probably be in core:
webpack/webpack#13252 (comment)
So I guess once this resolver plugin exists, if it won't be enabled automatically (which would be ideal), loaders who consume TS should verify that this resolver plugin is enabled.