Skip to content

Dynamic import not working on eval/print #30591

@jkrems

Description

@jkrems
  • Version: 13.2.0
  • Platform: macOS
  • Subsystem: modules
$ node --input-type=module -p "import('fs')"
Promise {
  <rejected> TypeError [ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING]: A dynamic import callback was not specified.
      [...] {
    code: 'ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING'
  }
}

$ node -e "import('fs')"
(node:41604) UnhandledPromiseRejectionWarning: TypeError [ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING]: A dynamic import callback was not specified.
    at exports.importModuleDynamicallyCallback (internal/process/esm_loader.js:35:9)

$ node --input-type=module -e "import 'path'; import('fs')"
(node:42773) UnhandledPromiseRejectionWarning: TypeError [ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING]: A dynamic import callback was not specified.

The last one seems the most confusing: The same input string works fine with static import but not with dynamic import from the same file. I assume this is a side-effect of tying the import callback to individual scripts instead of to the context.

Metadata

Metadata

Assignees

No one assigned

    Labels

    cliIssues and PRs related to the Node.js command line interface.esmIssues and PRs related to the ECMAScript Modules implementation.experimentalIssues and PRs related to experimental features.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions