egoist / egoist/tsup

Source maps not being generated when using `outExtension { js: ".jsx" }`

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

Description

## What's the problem?

When using `outExtension: () => ({ js: ".jsx" })` Tsup doesn not generate source maps. The build works but the missing source maps lead to a very bad debugging experience for us. Would be great to have these for jsx outputs as well.

## Longer Story

We're using SolidJS and need to preserve the JSX in library code of a big monorepo. The libs are built with tsup while the application is built with vite. The application uses `vite-plugin-solid` which expects all library code expose the unbuilt jsx and then builds the JSX in files with `.jsx` extensions in one batch. The build works but the missing source maps lead to a very bad debugging experience for us.

## Reproduction

```tsx
// tsup.config.ts
import { defineConfig } from "tsup";

export default defineConfig({
format: "esm",
entry: ["src/index.tsx"],
outDir: "out",
sourcemap: true,
esbuildOptions(es_options) {
es_options.jsx = "preserve";
},
outExtension: () => ({ js: ".jsx" }),
});
```

```tsx
// src/index.tsx
export function Component() {
return

Hello
;
}
```

```json
// package.json
{
"name": "lib",
"type": "module",
"exports": "./out/index.jsx",
"scripts": {
"build": "tsup"
},
"dependencies": {
"solid-js": "~1.9.4"
},
"devDependencies": {
"typescript": "~5.2.2",
"tsup": "~8.3.6"
}
}

```

Now run tsup

### Expected behavior

The `out` folder should contain `index.jsx` and `index.jsx.map`.

### Actual behavior

The `out` folder only contains `index.jsx` and no `index.jsx.map`.

### Narrowing it down

When commenting out the `outExtension` option in the `tsup.config.ts` the maps start appearing.

## Additional info

It does not seem to be an upstream esbuild problem. I ran esbuild with the same config that tsup calls it with and the source maps were there. They aren't when run through tsup though. I think the issue might lie in the this code that's responsible for writing to disc https://github.com/egoist/tsup/blob/0328fd64a771adb0789968775c22b4317683fafe/src/plugin.ts#L131-L225

Contributor guide

Open the contributing guide

Research direction

Start with the reproduction in tsup.config.ts and src/index.tsx, run tsup with sourcemap enabled and outExtension set to .jsx, then inspect src/plugin.ts around lines 131-225. Done means the out directory contains both index.jsx and index.jsx.map, while the existing build output remains functional.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.