microsoft / microsoft/TypeScript
`moduleResolution: bundler` diverges from bundlers following node semantics in regards to `default` import
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
Bug Report
🔎 Search Terms
moduleResolution bundler node webpack default namespace
🕗 Version & Regression Information
- This is the behavior in every version I tried: 5.0.4 (the only one with
moduleResolution: bundler
⏯ Playground Link
Repro case can be found here
🙁 Actual behavior
When resolving a .d.mts file that proxies to .d.ts in a CJS package with moduleResolution: bundler, TypeScript complains with an error like:
Property 'default' does not exist on type 'string'.ts(2339)
The reason that it complains about it is that TypeScript is resolving default import as if the .d.ts in this CJS package could export the "real" default export. webpack actually follows semantics coined by node and it loads the namespace object as the default export of that "cjs file".
So the type-level reality diverges there from runtime. At runtime, with webpack - it works exactly like it would work in node. TypeScript thinks that the intention was to load module.exports.default there though.
🙂 Expected behavior
I'm not exactly sure what's the expected behavior here because "resolving" like a bundler is quite under-specified and bundlers are not quite consistent when it comes to this. Even when we check this very same repro, we can see that I had to use defaultIsModuleExports: true in Rollup for it to behave the same. By default, Rollup behaves in the same way as TypeScript does.
cc @andrewbranch
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza ejecutando el repro enlazado y siguiendo la resolución desde el proxy .d.mts hasta el archivo .d.ts con moduleResolution: bundler. Compara el resultado observado de TypeScript con webpack, la semántica de Node y el comportamiento documentado de Rollup. Para darlo por terminado se requieren un comportamiento esperado acordado y un caso de regresión, pero el issue no identifica los archivos de código fuente o de pruebas relevantes.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- node.js, rollup, typescript, webpack
- Área
- compilers
- Tipo de issue
- Error
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Necesita aclaración
- Aptitud para principiantes
- 20/100