-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
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
-
Offer a solution that actually has a chance of working (I can’t rename a typescript file to .cjs or .mjs)
-
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:
rollup/cli/run/loadConfigFile.ts
Lines 127 to 129 in bf1ff32
| 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.