Support node16+ `moduleResolution` in ESM directories through named exports
Rollup Plugin Name: {name}
This PR contains:
- [ ] bugfix
- [x] feature
- [ ] refactor
- [ ] documentation
- [ ] other
Are tests included?
- [ ] yes (bugfixes and features will not be merged without tests)
- [x] no - read on! :)
Breaking Changes?
- [ ] yes (breaking changes will not be merged unless absolutely necessary)
- [x] no
If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.
List any relevant issue numbers:
Fixes #1541, #1578 Supersedes #1744, #1782
Description
Since #1782 is still failing in CI and since I still have no idea how to fix it, this new PR is a shameful attempt to work around the issue by providing named exports for all plugins, in addition to the default export.
// ❌ fails with `type="module"` and `moduleResolution="node16"`
import typescript from '@rollup/plugin-typescript'
// ✅ works everywhere
import { typescript } from '@rollup/plugin-typescript'
I've also added a note in each README.md, right below the usage example, that reads like this:
[!NOTE] If your editor complains that "XXX is not a function", then use the named export instead:
import { XXX } from '@rollup/plugin-XXX';
Because there is absolutely no code change except for an additional export of the main factory function, I don't think new tests are necessary here. Please let me know if you feel otherwise.
Appreciate the additional effort here, but we need a different direction so we're not dealing with bandaids.
Node 20.19.0 released proper compatibility for importing/requiring EMS from CJS. Now that Node 18 is out of LTS, we can safely enforce Node 20.19.0 as the minimum version. That means there's no reason for this repo to ship support for both CJS and ESM anymore.
What the project needs is for every plugin to be authored in TS and updated to ship only ESM. That should nuke any TS compat issues as well as bring the repo up to date. (For what it's worth, this is also something that needs to happen on a per-package basis, not a single PR that updates the world at once)
Well, I tried 😅
Agreed, this is the way to go. Any ETA about this? Do you need any help?
@Septh I'll try and tackle this at some point this week. I'm planning on going one plugin at a time. If you'd like to begin that process, please feel free. I do want to avoid a large PR with many plugins affected at once.
Sorry for the late reply, I've been quite busy these last days.
If you'd like to begin that process, please feel free.
Yes, I am willing to contribute! Maybe we should synchronize so we don't both work on the same plugins. Any suggestions as to which packages I could start with?
What the project needs is for every plugin to be authored in TS and updated to ship only ESM. That should nuke any TS compat issues as well as bring the repo up to date. (For what it's worth, this is also something that needs to happen on a per-package basis, not a single PR that updates the world at once)
wrong! @rollup/plugin-node-resolve works perfectly fine in esm and cjs. This PR is great, you guys just find reasons not to change anything. I remember having this issue 2 years ago and now here's approaching 2026 and most package are not even modern JS friendly... come on:)