node-semver
node-semver copied to clipboard
[BUG] the package isn't compatible with Rollup due to require cycle
What / Why
Rollup breaks this package when bundling it.
When
Since 2021-07-05 when @rollup/plugin-commonjs
19.0.0 has been released.
How
Current Behavior
semver.satisfies
always returns false
after bundling with Rollup.
Steps to Reproduce
- Clone https://github.com/thorn0/rollup-commonjs-semver-issue and install the dependencies.
- Try running unbundled
input.js
. It works correctly. - Try running bundled
output.js
. Its output is incorrect. - You can perform the bundling yourself by running
index.mjs
.
Expected Behavior
Bundled and unbundled code should work the same way.
References
- https://github.com/rollup/plugins/issues/879
- There is a solution proposed in https://github.com/rollup/plugins/issues/879#issuecomment-836612918
- https://github.com/npm/node-semver/issues/318
Any news or working workaround ?
Sounds like you need to file a bug on rollup then?
Importing one by one fixed this for me:
import maxSatisfying from "semver/ranges/max-satisfying";
import minSatisfying from "semver/ranges/min-satisfying";
import coerce from "semver/functions/coerce";
Facing the issue when trying to rollup a fastify server which depends on this package. If what @Idered mentioned is correct then I suppose the fix has to go to the packages that depends on semver, fastify in my case? Does anyone have more insight on what is going wrong?
Ran into this issue today. Not a blocker for us but it would be nice to eliminate the cycle warning. Wondering if the solution proposed by @lukastaegert has been considered/attempted? (It doesn't appear that it has.)
I suppose the main issue is creating a breaking change for third-party code that imports Range and Comparator. Unfortunately I'm not familiar enough with this library yet to know what that impact would likely be, and what the workarounds might be.
Importing one by one fixed this for me:
import maxSatisfying from "semver/ranges/max-satisfying"; import minSatisfying from "semver/ranges/min-satisfying"; import coerce from "semver/functions/coerce";
thanks. I fixed the problem use this solution. But, I don't understand why. Can you explain it? @Idered Idered