Skip to content

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

Open

Description

@thorn0

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

Expected Behavior

Bundled and unbundled code should work the same way.

References

Activity

  1. aurelhann commented on Aug 24, 2021

    @aurelhann

    Any news or working workaround ?

  2. ljharb commented on Aug 24, 2021

    @ljharb
    Contributor

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

  3. Idered commented on Sep 25, 2021

    @Idered

    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";
  4. himanshusinghs commented on Jan 24, 2022

    @himanshusinghs

    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?

  5. changed the title [-][BUG] the package isn't compatible with Rollup[/-] [+][BUG] the package isn't compatible with Rollup due to require cycle[/+] on Feb 26, 2022
  6. hadfieldn commented on May 3, 2022

    @hadfieldn

    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.

  7. rosefang commented on Jun 28, 2022

    @rosefang

    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

  8. added this to the v8 milestone on Oct 31, 2022
  9. mbtools commented on May 21, 2026

    @mbtools
    Contributor

    This was 5y ago.

    I tested this with latest version of rollup (4.60.4), the plugins, and semver. It now works correctly.

    I suggest closing this issue.

    Before

    https://github.com/thorn0/rollup-commonjs-semver-issue

    > node .\input.js
    true
    > node .\output.mjs
    false

    After

    https://github.com/mbtools/rollup-commonjs-semver-issue

    You do get a message about the circular dependency but the bundled code works fine:

    > node .\input.js
    true
    > node .\index.mjs
    Circular dependency: node_modules/semver/classes/comparator.js -> node_modules/semver/classes/range.js -> node_modules/semver/classes/comparator.js
    > node .\output.mjs
    true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingsemver:majorbackwards-incompatible breaking changes

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions