egoist / egoist/tsup

Enabling `bundle: false` does not add import extensions in ESM files

Open
#953 21 comments 29 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
11.3k
Forks
275
PR merge metrics
No merged PRs in 30d

Description

I've noticed this bug after merging the following PR: https://github.com/TanStack/query/pull/5597

When `bundle: true` is set, `index.js` (ESM) file looks like this:

```
import "./chunk-55J6XMHW.js";
import {
QueriesObserver
} from "./chunk-FVYPMHO2.js";
import {
QueryClient
} from "./chunk-6F4EPMPD.js";
import {
QueryCache
} from "./chunk-5EQKN4WB.js";
import "./chunk-CSKZ3U2N.js";
...
```

When `bundle: false` is set, `index.js` (ESM) file looks like this:

```
import { CancelledError } from "./retryer";
import { QueryCache } from "./queryCache";
import { QueryClient } from "./queryClient";
import { QueryObserver } from "./queryObserver";
import { QueriesObserver } from "./queriesObserver";
import { InfiniteQueryObserver } from "./infiniteQueryObserver";
...
```

I expected that tsup would also add the required `.mjs` (or `.js` when `"type": "module"` is set) to relative imports within the project, like rollup did. This causes import errors when imported in ESM projects (e.g. Vite). For now, I've added https://github.com/favware/esbuild-plugin-file-path-extensions, but this seems to force override some tsup settings.

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with tsup configured with bundle: false and inspect the generated index.js ESM imports, comparing them with the bundle: true output. Verify the fix by importing the generated package from an ESM project such as Vite and confirming relative imports resolve with the required extensions.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.