babel-plugin-module-resolver icon indicating copy to clipboard operation
babel-plugin-module-resolver copied to clipboard

ESM package + TypeScript support

Open ntucker opened this issue 3 years ago • 0 comments

Motivation

With TypeScript 4.7 the ESM world is getting serious: https://devblogs.microsoft.com/typescript/announcing-typescript-4-7-beta/#esm-nodejs

Building an ESM package ("type": "module") requires imports to contain a ".js" at the end. To make this work in TypeScript, you can import "myModule.js" and the real file is "myModule.tsx". One could simply use TSC then to compile properly. However, some of us like using babel for the compilation step.

Everything works fine in fact if I just add .js as the output files work perfectly. However, when I run something like jest it breaks.

Cannot find module './entities/Entity.js' from 'packages/normalizr/src/denormalize.ts'

(./entities/Entity.ts is the actual file)

Solution

It would be nice to have a simple way to either add ".js" extension for extensionless imports - or lookup other extensions when a ".js" exists in an import.

ntucker avatar Apr 20 '22 18:04 ntucker