Skip to content

--experimental-vm-modules on Node 12 results in confusing dynamic callback error #33202

@SimenB

Description

@SimenB
  • Version: v12.16.3
  • Platform: macOS
  • Subsystem: ESM

What steps will reproduce the bug?

// file.js
import('fs')
  .then(() => {
    console.log('yay!');
  })
  .catch(error => {
    console.error('aww', error);
    process.exitCode = 1;
  });

Node 12 still has flagged ESM, so running this file results in the following:

$ node file.js
aww Error: Not supported
    at Object.<anonymous> (/Users/simen/oops/file.js:1:1)
    at Module._compile (internal/modules/cjs/loader.js:1133:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
    at Module.load (internal/modules/cjs/loader.js:977:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47

However, if you add --experimental-vm-modules, the error gets very confusing.

$ node --experimental-vm-modules file.js
aww TypeError [ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING]: A dynamic import callback was not specified.
    at exports.importModuleDynamicallyCallback (internal/process/esm_loader.js:35:9)
    at Object.<anonymous> (/Users/simen/oops/file.js:1:1)
    at Module._compile (internal/modules/cjs/loader.js:1133:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
    at Module.load (internal/modules/cjs/loader.js:977:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47 {
  code: 'ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING'
}

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

It always reproduces

What is the expected behavior?

Node should give the same warning as if the flag wasn't passed.

What do you see instead?

Node throws ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING instead.

Additional information

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    vmIssues and PRs related to the vm subsystem.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions