Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

typescript-transformer-esm

carlocorradini785MIT1.1.0

Make import/export ESM compatible by appending .js (file) or /index.js (directory)

esm, export, import, modules, plugin, transformer, typescript

readme

typescript-transformer-esm

ci

Inspired by @zoltu/typescript-transformer-append-js-extension and @nvandamme/typescript-transformer-append-js-extension

Make import/export ESM compatible by appending .js (file) or /index.js (directory).

Why? TypeScript's issues 783 and 16577 have been closed.

Example

Source (TypeScript):

import a from "./file";
import b from "./directory";

Compiled (JavaScript):

import a from "./file.js";
import b from "./directory/index.js";

Usage

Warning: Make sure "module": "esnext" is present in tsconfig.json

Note: Compatible with typescript-transform-paths

  1. Install

    npm install --save-dev typescript-transformer-esm
  2. Install dependencies

    ts-patch or ttypescript

    • ts-patch

      npm install --save-dev ts-patch && npx ts-patch install -s
    • ttypescript

      npm install --save-dev ttypescript
  3. Update tsconfig.json

    {
      "compilerOptions": {
        "module": "esnext",
        // ...
        "plugins": [
          {
            "transform": "typescript-transformer-esm",
            "after": true
          }
        ]
      }
    }
  4. Compile

    • ts-patch

      npx tsc --build tsconfig.json
    • ttypescript

      npx ttsc --build tsconfig.json

Contributing

I would love to see your contribution :heart:

See CONTRIBUTING guidelines.

License

This project is licensed under the MIT License. \ See LICENSE file for details.

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[Unreleased]

v1.0.0 - 2023-03-31

  • Initial release