Skip to content

VM Module linking unclear error message #60157

Description

@blikest

Version

24.9.0

Platform

Linux x64

Subsystem

vm

What steps will reproduce the bug?

  1. Instantiate a SourceTextModule importing other normal modules from filesystem.
  2. An unintelligible erroris thrown when linking a seemingly normal, second-layer dependency without further imports.
    My implementation based on the docs is roughly:
 export async function modularise(resource,identifier,context={},depth=0)
{// uses --experimental-vm-modules 
 let {SourceTextModule,SyntheticModule,createContext,isContext}=await import("vm");
 let {pathToFileURL}=await import("url");
 let synthetic=!resource&&/^[a-z]/.test(identifier);
 if(!synthetic)
 identifier=await resolve("path","resolve",identifier)
,resource=await fs.read(identifier,"utf8");
 if(!isContext(context))
 context=createContext({imports:{},...context});
 let precedent=context.imports[identifier];
 if(precedent)
 return precedent;
 let module=synthetic
?await import(identifier).then(module=>new SyntheticModule(Object.keys(module),function()
{Object.entries(module).reduce((module,entry)=>
 module.setExport(...entry)||module
,this);
},{identifier,context}))
:new SourceTextModule(resource||""
,{identifier,context
 ,importModuleDynamically:specifier=>import(specifier)//compose(link,"namespace")({specifier})
 ,initializeImportMeta:meta=>Object.assign(meta,{url:pathToFileURL(identifier)})
 });
 merge(context.imports,module,[identifier]);
 let links=await module.moduleRequests?.reduce(record(({specifier})=>
 modularise(null,specifier,context,depth+1)),[]);
 await module.linkRequests?.(links);
 module.instantiate?.();
 if(!depth)
 await module.evaluate();
 return module;
};

logged import graph:

first.js (unlinked) ➡️ middle.js (unlinked) ➡️ third.js (linked)
                                                   ⬆️
                                            ➡️ neighbor. js (unlinked)

Error received when instantiating middle.js:

[ERR_VM_MODULE_LINK_FAILURE] request for './third.js' is from a module not been linked
  at module.instantiate?.()

How often does it reproduce? Is there a required condition?

consistently with the given module graph

What is the expected behavior? Why is that the expected behavior?

Error message in more correct English, since third.js is in fact in linked status, and middle.js is only not because that's the one being instantiated.
Or is it a problem that middle.js remains in unlinked stage after linkRequests?...

What do you see instead?

The error message should at least be more clear. "from a module not yet linked" perhaps?

Additional information

No response

Activity

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

    vmIssues and PRs related to the vm subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions