Skip to content

Error TRANSPILED_ESM_CONFIG provides insufficient information #4616

@flying-sheep

Description

@flying-sheep

Rollup Version

2.78.1

Operating System (or Browser)

Linux/Firefox

Node Version (if applicable)

No response

Link To Reproduction

https://replit.com/@flying-sheep/rollup-repro-esm-from-ts

Expected Behaviour

Until fixing the underlying bug #4617, I’d expect the error message to

  1. Offer a solution that actually has a chance of working (I can’t rename a typescript file to .cjs or .mjs)

  2. The actual problem can only be debugged knowing the content of the discarded original error’s message, which tells me which imported module causes the error.

    Error: require() of ES Module <projdir>/node_modules/@mdx-js/rollup/index.js from <projdir>/rollup.config.ts not supported.
    Instead change the require of index.js in <projdir>/rollup.config.ts to a dynamic import() which is available in all CommonJS modules.
    

Actual Behaviour

An encountered node error with code ERR_REQUIRE_ESM gets converted into a rollup error with code TRANSPILED_ESM_CONFIG, in the process discarding vital information to figure out where that happened:

message: `While loading the Rollup configuration from "${relativeId(
fileName
)}", Node tried to require an ES module from a CommonJS file, which is not supported. A common cause is if there is a package.json file with "type": "module" in the same folder. You can try to fix this by changing the extension of your configuration file to ".cjs" or ".mjs" depending on the content, which will prevent Rollup from trying to preprocess the file but rather hand it to Node directly.`,

I encountered this utterly unhelpful error,

[!] Error: While loading the Rollup configuration from "rollup.config.ts",
Node tried to require an ES module from a CommonJS file, which is not supported.
A common cause is if there is a package.json file with "type": "module" in the same folder.
You can try to fix this by changing the extension of your configuration file to ".cjs" or ".mjs" depending on the content,
which will prevent Rollup from trying to preprocess the file but rather hand it to Node directly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions