Remove runtime code for exports in CommonJS output
- Dominant language
- Go
- Stars
- 40.1k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
[Node.js can, to some extent, statically analyze exports when importing CJS from ESM, allowing for namespace imports](https://nodejs.org/api/esm.html#esm_commonjs_namespaces)
esbuild currently generates runtime code that the static analyzer fails to recognize,
```js
var __defProp = Object.defineProperty;
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
var __export = (target, all) => {
__markAsModule(target);
for (var name in all)
__defProp(target, name, {get: all[name], enumerable: true});
};
__export(exports, {
parse: () => parse
});
function parse () {}
```
When imported from ESM
```
[Module: null prototype] { default: { parse: [Getter] } }
```
Is there a possibility that these can be omitted altogether?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the CommonJS-to-ESM import behavior described in the issue and compare it with Node.js's static export analysis documentation. Trace where esbuild emits the shown CommonJS export helpers; done means determining whether they can be removed while preserving the reported export behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, javascript, node.js
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100