Skip to content

node --experimental-modules main doesn't work (works only if extension supplied) #16476

Description

@giltayar
  • Version: v8.8.0
  • Platform: macOS
  • Subsystem: ES Modules

Assuming the simple file main.mjs:

console.log('hi')

Running node --experimental-modules main.mjs will work, but node --experimental-modules main won't work. You get:

{ Error: Cannot find module file:///********/main
    at module.exports (internal/loader/search.js:14:12)
    at exports.resolve (internal/loader/ModuleRequest.js:93:11)
    at Loader.resolve (internal/loader/Loader.js:51:40)
    at Loader.getModuleJob (internal/loader/Loader.js:79:40)
    at Loader.import (internal/loader/Loader.js:101:28)
    at module.js:454:29
    at Function.Module._load (module.js:455:7)
    at Function.Module.runMain (module.js:653:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3 code: 'MODULE_NOT_FOUND' }

This is true even if the extension of the file is js.

This is a regression - it works fine in v8.7.

If it's a feature and not a bug, then it doesn't make sense to me, as importing the same file without an extension works fine - and I believe running a file in the command line and importing it should have similar semantics.

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

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions