egoist / egoist/tsup

`.mjs` files getting automatically renamed after build

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

Description

I'm having a *really* weird issue where my `.mjs` files gets renamed to `.js` after tsup finishes building.

My `tsup.config.ts`:

```typescript
import { defineConfig, type Options } from "tsup";

export default defineConfig((options: Options) => ({
clean: true,
format: ["esm"],
...options,
}));
```

It goes like this:

```bash
$ tsup --onSuccess "ls dist" src # This will list files in dist/ after building
CLI Building entry: src/index.ts
CLI Using tsconfig: tsconfig.json
CLI tsup v8.0.2
CLI Using tsup config: ...
CLI Target: es2022
CLI Cleaning output folder
ESM Build start
ESM dist/index.mjs 743.75 KB
ESM ⚡️ Build success in 46ms
index.mjs # <-- Note the .mjs extension

$ ls dist
index.js
```

The file is mysteriously renamed. So when you do:

```bash
$ tsup --onSuccess "node dist/index.mjs" src
```

It will fail because the file is no longer there. `node dist/index.js` doesn't work either, so I suspect there is a small window where the file just doesn't exist. Does anyone know why this is happening?

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with tsup.config.ts, src/index.ts, and the shown --onSuccess commands, checking the contents of dist before and after the callback. Trace why the build reports index.mjs but the callback observes a different output, and consider the issue done when the documented command consistently leaves the expected module available to onSuccess.

Written by the indexing model from the issue text.

Assessment

Tech stack
nodejs, typescript
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.