node-semver icon indicating copy to clipboard operation
node-semver copied to clipboard

[BUG] the package isn't compatible with Rollup due to require cycle

Open thorn0 opened this issue 3 years ago • 6 comments

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

thorn0 avatar May 10 '21 21:05 thorn0

Any news or working workaround ?

aurelhann avatar Aug 24 '21 08:08 aurelhann

Sounds like you need to file a bug on rollup then?

ljharb avatar Aug 24 '21 14:08 ljharb

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";

Idered avatar Sep 25 '21 21:09 Idered

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?

himanshusinghs avatar Jan 24 '22 21:01 himanshusinghs

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.

hadfieldn avatar May 03 '22 19:05 hadfieldn

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

rosefang avatar Jun 28 '22 12:06 rosefang