Skip to content

Very confusing message when user doesn't realize they're in a CommonJS context #50009

Closed
@DanielRosenwasser

Description

@DanielRosenwasser

Found from an issue I was diagnosing for @mpodwysocki.

Today, if you use "module": "nodenext" or "module": "node16", you might try to import from a package with ESM files and get the following error message

Module 'yadda/file.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead.

This is extremely confusing. The fix is typically to add the following field to the package.json that corresponds to the importing file with the error:

    "type": "module"

Metadata

Metadata

Assignees

Labels

Domain: ES ModulesThe issue relates to import/export style module behaviorDomain: Error MessagesThe issue relates to error messagingEffort: CasualGood issue if you're already used to contributing to the codebase. Harder than "good first issue".Fix AvailableA PR has been opened for this issueHelp WantedYou can do this

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions