Skip to content

ESM package + TypeScript support #435

@ntucker

Description

@ntucker

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions