Skip to content

Wildcard replacement is broken #76

Closed

Description

@AdaptivChris

When using conditional exports and wildcard in package.json with esmock, I stumbled upon this issue:
resolvewithplus.js#L224
sould be slice(0,-asteriskAfter.length); to retrieve the non-suffix part instead of the suffix part.

Activity

  1. iambumblehead commented on May 27, 2026

    @iambumblehead
    Owner

    @AdaptivChris would you show me how to reproduce the issue? An example of what the package.json export should look like and what the javascript import-statement look like would probably be sufficient for reproducting. Thanks for opening the issue.

  2. AdaptivChris commented on May 27, 2026

    @AdaptivChris
    Author

    Of course, in a node module, have a package.json like this:

    {
      "exports": {
        "./*.mjs": {
          "default": "./dist/*.mjs"
        }
    }
    

    Now you can import any file in the node_modules/{module}/dist/x.mjs as import X from 'module/x.mjs;.
    But if you try to mock it with esmock you will get an error regarding .../dist/js.mjs file not existing.

    This is due to './x.mjs' being cut to '.mjs' in the faulty line, and then cut again the next line to 'js', which then replace the asterix, so we get the path .../dist/js.mjs

    Strangely enough, using the non conditional export "./*.mjs": "./dist/*.mjs" works.

  3. iambumblehead commented on May 27, 2026

    @iambumblehead
    Owner

    I'll try to make a reproduction

  4. AdaptivChris commented on May 27, 2026

    @AdaptivChris
    Author

    index.mjs:

    import esmock from "esmock";
    await esmock("./file.mjs", {"x/x.mjs": {default: () => {return "mocked";}}});
    

    file.mjs:

    import X from "x/x.mjs";
    

    node_modules/x/package.json:

    {
      "exports": {"./*.mjs":{"default":"./dist/*.mjs"}}
    }
    

    node_modules/x/dist/x.mjs:

    export default function() {return "x";}
    
  5. iambumblehead commented on May 27, 2026

    @iambumblehead
    Owner

    still investigating, but following your instructions here #80

  6. iambumblehead commented on May 27, 2026

    @iambumblehead
    Owner

    the test seems to reproducing the issue. this one works

     "exports": {"./*":{"default":"./dist/*"}}

    this one fails,

    "exports": {"./*.mjs": {"default":"./dist/*.mjs"}}
  7. iambumblehead commented on May 28, 2026

    @iambumblehead
    Owner
  8. added a commit that references this issue on May 30, 2026
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions