Skip to content
This repository was archived by the owner on Sep 2, 2023. It is now read-only.
This repository was archived by the owner on Sep 2, 2023. It is now read-only.

Warn if ESM is used in .js #131

@xtuc

Description

@xtuc

I expected that many users will be confused by .mjs and ESM.

Here's an example:

root
├── a.js
Details export const a = 1;
└── index.mjs
Details import {a} from "./a.js" console.log(a);

When running this with node --experimental-modules index.mjs, the error is the following:

(node:9967) ExperimentalWarning: The ESM module loader is experimental.
file:////test/index.mjs:1
import {a} from "./a.js"
        ^
SyntaxError: The requested module './a.js' does not provide an export named 'a'
    at ModuleJob._instantiate (internal/modules/esm/module_job.js:89:21)

While importing ./a.js is not an error (since CJS interop), it's clear that the user intended to use ESM. It would make sense to warn the user.

Note that .js/.mjs is not clear in tooling yet (Babel), so it could end up being generated.

(node v10.4.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions