ESM loader to transform imports using ESBuild
npm install esbuild-esm-loaderESBuild ESM Loader is a custom resolver implementation for the module customization hooks feature of Node.js ECMAScript modules.
Using this loader will enhance the default loader behavior to allow you to transform imported files using ESBuild, allowing for transparent imports of modern JavaScript, JSX, and TypeScript.
``tsx
// index.tsx
import React from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
console.log(renderToStaticMarkup(
`
node --import=esbuild-esm-loader/register ./index.tsx
`Installation
The current version of the library requires Node.js v16.17 or newer.
Install as a dependency using
npm. You will also need to install ESBuild, as it's a peer dependency of this project.`
npm install esbuild esbuild-esm-loader
`Usage
Loaders can be defined as an argument when running
node.`
node --import=esbuild-esm-loader/register entry.js
`For better error stack traces, this loader supports Node.js's native sourcemap support, which can be enabled by passing the
--enable-source-maps flag.`
node --enable-source-maps --import=esbuild-esm-loader/register entry.js
`Configuration
If present, a
tsconfig.json will be read and provided to ESBuild as the tsconfigRaw option. You can use this to control behavior such as JSX pragma with TypeScript's jsxFactory` configuration option. This applies even if you are not using TypeScript.This project follows Semantic Versioning.
To better align with the experimental status of the loader hooks, initial releases will follow major version zero until the feature stabilizes in Node.js. Minor versions on the zero major will always include breaking changes. Patch versions on the zero major will include bug fixes and backwards-compatible changes.
Versioning will proceed from 1.0.0 once the feature stabilizes in Node.js.
Copyright 2025 Andrew Duthie
Released under the MIT License. See LICENSE.md.