Skip to content

Adopt tsup, esbuild or vite for Cleaner ESM Builds and Extensionless Imports #110

Description

@ionleu

What's the problem?

We're currently using Node.js with "type": "module" and moduleResolution: "node16", which requires explicitly adding .js extensions in all ESM imports. This leads to cluttered and brittle import statements, especially when working in TypeScript where the source files are .ts but get compiled to .js.

Maintaining these extensions manually:

  • Hurts developer experience (DX)
  • Causes confusion during refactors/renames
  • Doesn't align with the clean, extensionless style we're used to in CommonJS or legacy TypeScript setups

What's your solution?

Adopt a bundler like tsup, esbuild or vite in our build pipeline to:

  • Allow us to write clean, extensionless imports in .ts source files
  • Automatically rewrite those to proper .js extensions in the output
  • Support modern ESM and fast builds
  • Maintain compatibility with "type": "module" and Node.js ESM requirements

This keeps dev DX clean and avoids runtime errors or path issues after compilation.

Any alternatives?

  1. Stick with manual .js extensions
    • Functional but error-prone and ugly.
  2. Switch back to CommonJS ("module": "CommonJS")
    • Avoids the extension issue, but sacrifices ESM features like top-level await.
  3. Use .ts extensions in dev (allowImportingTsExtensions)
    • Only works at compile time, breaks at runtime.

Anything else?

Here's an example tsup config we could use:

// tsup.config.ts
import { defineConfig } from 'tsup';

export default defineConfig({
	entry: ['src/index.ts'],
	format: ['esm'],
	target: 'es2022',
	dts: true,
	splitting: false,
	sourcemap: true,
	clean: true,
	outDir: 'dist',
});

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestimprovementsImproves the existing feature

Type

Fields

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions