Skip to content

Conversation

@rtritto
Copy link
Contributor

@rtritto rtritto commented Jan 20, 2026

Description

Replace gen-esm-wrapper with rollup

Related:

Checklist

@rtritto
Copy link
Contributor Author

rtritto commented Jan 20, 2026

Please update package-lock.json with npm i

FYI @addaleax

@addaleax
Copy link
Collaborator

As you can see, this PR isn't currently passing CI. I think rollup is having trouble with our typescript config?

In any case, I'm not sure how I feel about replacing our tooling because of rolldown not being able to handle CJS where Object.defineProperty() is used. That seems like a deficiency in rolldown, not in our tooling here?

@rtritto
Copy link
Contributor Author

rtritto commented Jan 21, 2026

As you can see, this PR isn't currently passing CI. I think rollup is having trouble with our typescript config?

I know, the package-lock.json needs to be updated, I can't do because the scripts fail on my Windows machine. You can run npm i to update package-lock.json and then commit it.

In any case, I'm not sure how I feel about replacing our tooling because of rolldown not being able to handle CJS where Object.defineProperty() is used. That seems like a deficiency in rolldown, not in our tooling here?

Seems that tsc (CJS) adds Object.defineProperty and then gen-esm-wrapper adds the ESM wrapper.
Object.defineProperty should be used only with CJS and not with ESM: I have the issue with rollup (ESM) and Object.defineProperty.

With this PR, you can also check inside the dist folder generated by rollup:

  • cjs/index.js has 1 Object.defineProperty
  • esm/index.js hasn't Object.defineProperty

Actually Object.defineProperty was used only here, I don't know if this needs a refactoring.

We need two different builds (CJS and ESM) or only ESM (new versions of devtools-shared tools as breaking change).


We can use directly a build tool (gen-esm-wrapper will not be needed): I used rollup because it's used by bson, feel free to use other alternatives (rolldown, tsdown, esbuild, pkgroll etc).

@addaleax
Copy link
Collaborator

Object.defineProperty should be used only with CJS and not with ESM

Right, the problem with rollup is that Object.defineProperty(exports, ...) is only being used with CJS and not with ESM.

What rollup doesn't support is importing from an CJS module that uses this; but that's a deficiency in rollup (or at least I can't see why it wouldn't be – default imports from CJS should be something that bundlers support unambiguously).

Using split builds might be the way to go in the long run, but it has its non-trivial downsides (e.g. object identity changing between the builds) and I'm not sure that it's a road we'd want to go down without discussing it on the team first

@rtritto
Copy link
Contributor Author

rtritto commented Jan 23, 2026

Using split builds might be the way to go in the long run, but it has its non-trivial downsides (e.g. object identity changing between the builds) and I'm not sure that it's a road we'd want to go down without discussing it on the team first

Please can a discussion/issue be opened?
This issue blocks all my projects.

@rtritto
Copy link
Contributor Author

rtritto commented Jan 29, 2026

@kmruiz @Anemy @nbbeeken Please anyone can open a related discussion/issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants