@repugraf/rewrite-esm-paths
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Rewrite ESM Paths

This issue this package is solving mostly caused typescript inability to rewrite imports/exports when building to esm target.


Example

This TypeScript code:

import Package from "./package";

Will stay the same when built to esm. This will not work when running inside nodejs in esm context.

Here is the desired output:

import Package from "./package.js";

More info about this issue can be found on this thread


Usage

import { resolve } from "fs";
import { addExtToFilesRecursive } from "@repugraf/rewrite-esm-paths";

const absoluteDirectoryPath = resolve(__dirname, "..", "lib", "esm");

addExtToFilesRecursive(absoluteDirectoryPath, "js");

Caveats

  • The package will not follow index.js imports. You need to specify full path to your files in your imports
  • Bare imports from node_modules will stay unchanged

Package Sidebar

Install

npm i @repugraf/rewrite-esm-paths

Weekly Downloads

1

Version

1.0.1

License

ISC

Unpacked Size

30.8 kB

Total Files

23

Last publish

Collaborators

  • repugraf