egoist / egoist/tsup

export default causes CommonJS bundles to include .default

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

Description

Adding `export default` to the main code causes CommonJS bundles to include .default and returns an error if not:
```
C:\Users\davet\Documents\sudokutest\index.js:15
console.log("Empty: ", sudoku.findAllEmpty(grid));
^

TypeError: sudoku.findAllEmpty is not a function
at Object. (C:\Users\davet\Documents\sudokutest\index.js:15:31)
at Module._compile (node:internal/modules/cjs/loader:1565:14)
at Object..js (node:internal/modules/cjs/loader:1708:10)
at Module.load (node:internal/modules/cjs/loader:1318:32)
at Function._load (node:internal/modules/cjs/loader:1128:12)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:219:24)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:170:5)
at node:internal/main/run_main_module:36:49

Node.js v22.12.0
```

With .default
![Image](https://github.com/user-attachments/assets/b258a2c1-cd62-4693-b5d8-936462d3d09f)
Without .default
![Image](https://github.com/user-attachments/assets/8e2f7103-3182-4120-ace3-7c48722084f4)

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the provided index.js CommonJS example under Node.js, then trace tsup's handling of export default in the CommonJS bundle. Done means the generated bundle exposes findAllEmpty directly, matching the no-.default example, without the reported TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.