Skip to content

Importing a ".js" using esm does not show error if imported file has an "export" decl #16474

Closed
@giltayar

Description

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

Assuming the following files:

// main.mjs
import {x} from './not-a-module.js'

// not-a-module.js
export const x;

One would expect that node --experimental-modules main.mjs would throw an error that not-a-module is not an ES module and thus does not support export. Rather, it throws this error:

SyntaxError: The requested module does not provide an export named 'x'
    at checkComplete (internal/loader/ModuleJob.js:86:27)
    at moduleJob.linked.then (internal/loader/ModuleJob.js:69:11)
    at <anonymous>

Note that running not-a-module.js as the main module does throw the expected error, i.e. node --experimental-modules not-a-module.js throws an err: SyntaxError: Unexpected token export.

Also note that node -r @std/esm does the right thing. Just sayin' :-).

Metadata

Metadata

Assignees

No one assigned

    Labels

    esmIssues and PRs related to the ECMAScript Modules implementation.stalledIssues and PRs that are stalled.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions