Skip to content

Fixes the file extensions in TypeScript files so they may be loaded as ES modules

Notifications You must be signed in to change notification settings

mothepro/tsc-esm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tsc-esm

Fixes the file extensions in TypeScript files so they may be loaded as ES modules.

⚠️ string literals may be affected by this ️️⚠️

ES Modules require imports to contain the file extension.

Currently, TypeScript doesn't add the file extensions for you. (issue) 🤞

Although, they could be added in the TS file this makes using the non-module (nodejs / mocha testing) difficult.

This simple program allows you to continue writing your TS files without the extension and will append .js to all your local imports.

Example

This:

import Default from "no-change";
import { func } from "./local/function";
// ...

Turns into:

 *  import Default from "no-change";
 *  import { func } from "./local/function.js";
// ...

Install

$ npm i -D tsc-esm

How to use

After you have compiled your TypeScript run it through this CLI.

$ tsc && tsc-esm index.js dist/*.js

TODO

  • Do not add extension if it already exists

About

Fixes the file extensions in TypeScript files so they may be loaded as ES modules

Resources

Stars

Watchers

Forks

Packages

No packages published