Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Glob imports must match exactly #3721

Open
hermanbanken opened this issue Apr 8, 2024 · 0 comments
Open

Glob imports must match exactly #3721

hermanbanken opened this issue Apr 8, 2024 · 0 comments

Comments

@hermanbanken
Copy link

hermanbanken commented Apr 8, 2024

Library redback has imports like this:

base.forEach(function (structure) {
    Redback.prototype.addStructure(structure,
        require('./base_structures/' + structure)[structure]);
});

The glob functionality (#2508) correctly finds the require and transforms it into:

// require("./base_structures/**/*") in node_modules/redback/lib/Redback.js
var globRequire_base_structures;
var init_ = __esm({
  'require("./base_structures/**/*") in node_modules/redback/lib/Redback.js'() {
    globRequire_base_structures = __glob({
      "./base_structures/Bitfield.js": () => require_Bitfield(),
      "./base_structures/Hash.js": () => require_Hash(),
      "./base_structures/List.js": () => require_List(),
      "./base_structures/Set.js": () => require_Set2(),
      "./base_structures/SortedSet.js": () => require_SortedSet()
    });
  }
});

However, this fails with this error due to the missing file extension:

throw new Error("Module not found in bundle: " + path2);
^
Error: Module not found in bundle: ./base_structures/Hash

Can globRequire be adjusted to support the common file extensions that require supports?

If the exact filename is not found, then Node.js will attempt to load the required filename with the added extensions: .js, .json, and finally .node. ref: official doc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant