-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
Trying to load two modules with the same URL throws an empty object #51694
Comments
May not seem like a huge deal at first, |
loosely related to nodejs/loaders#163 , in being my second encounter with an untracable error message from beyond the "load" hook in a load sequence. |
@nodejs/loaders |
I think that's the documented behavior: Lines 529 to 532 in ee5cfcb
|
does it have to throw an empty object at that point though? can't it spell out "import signature for {source} in {parentUrl} at {line:character} doesn't match the cached entry to resolve."? or if the intention behind including it in the cache key is that it should resolve different (even if the same) files by the given specifier, shouldn't it just differentiate and proceed with the hooks? which will then determine if they want to re-equivocate them from their own cache or sthing? |
You probably already know this, and I suppose it's your way for protesting lack of a good API in Node.js, but this is horrendous – and very fragile. Please, I'm begging you, don't do that in real code.
The empty object is definitely not supposed to happen, if someone wants to investigate that that'd be awesome.
Both imports should resolve to the same module, by spec, so loading a different module is not a supported use-case. Resolving modules is the mission of the |
haha you may assume more of me, either in smarts that i know what you mean or in stubbornness that i'm protesting; i don't see the fragility there, is it about the regexp? maybe the Thanks for confirming the rest. ps. if the specifier alone should exhaustively indicate module identity, i wonder why the attribute is part of the key. maybe it's just a hash of the arguments.. still my interpretation of import attributes was that it wouldn't be impossible for a file to contain ambiguous format (in a possible future where it's used for more than json, to load ambiguous syntaxes such as binaries, archives, symbolic links, vanilla vs type-annotations when native support lands for that, etc). anyway that's wild speculation, it's perfectly reasonable to assume one file stays in one format. |
Yes, file names can contain characters that have a special meaning in the context of a regex.
If you take the following code: await Promise.all({
import('someSpecifier'),
import('someSpecifier', { with: { type: 'json' }}),
]); You can imagine the race condition where we know |
In a loader module I'm handling sources with omitted
type
import attribute on JSON imports,by assigning
context.importAttributes.type
in the load hook, while caching the outputs.When the attributes are consistently omitted from JSON imports, or consistently aren't, this works well.
But when the import signature changes on one occasion, the process breaks
with an empty error object (
{}
) on returning the cached output.I can't tell the reason for this, for as far as the loader is concerned,
the load hook output should be idempotent whether the input
context.importAttributes.type
is defined or not:Here's a loader module to reproduce:
and here's a file with inconsistent attribute signatures to load
(in my real use case the inconsistency was in separate modules, one importing the other):
Result with node 21.1.0 (only notable difference is
<Buffer >
being empty innextLoad
's output already on the first import):node --watch --import=./loader.js ./loaded.js
The text was updated successfully, but these errors were encountered: