New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rollup throws TRANSPILED_ESM_CONFIG error when importing ESM module #4617
Comments
I very much recommend reading the documentation for this one: https://rollupjs.org/guide/en/#using-untranspiled-config-files Rollup CLI will also print this link to the documentation next to the error. |
As it is TypeScript, the only way to support this is via transpilation to CommonJS, unfortunately. The problem is that in order to run the transpiled file in position of the original file, we rely on a hack of Node's CommonJS API. The corresponding ESM API is still very experimental and cannot be used productively as far as I know, nor is it supported in any but the latest Node versions. You can however place your config in another folder with a package.json file with |
But wouldn't i still be unable to import that ESM module from commonjs? How can I configure rollup to compile a typescript config to ESM and use that? |
You just cannot at the moment. Currently, the best possibility for us would be to build upon this API https://nodejs.org/api/esm.html#loaders but not only is it experimental, but the need to configure it upfront via Node CLI flags makes it very hard to use. |
One escape hatch could be dynamic imports. I think they do not work at the moment because they are converted to require expressions during transpilation, but we can easily make them work by keeping them untranspiled in Rollup 3 and that would still be valid CommonJS. |
I think I understand the problems here now. On the other hand, the number of ESM only modules will only increase, and I don’t think forcing people to use CJS instead of typescript is a great thing. It seems impossible to do this at the moment, because rollup always compiles to CJS: rollup/cli/run/loadConfigFile.ts Line 87 in eb1fab7
Can you provide a CLI option to allow a workaround? |
Actually you made me think, and if we accept that we do it a little more slowly, we could just make it work by writing the transpiled file to disk and then dynamically importing it. If this works out, I will change the mechanism for Rollup 3 because you are right, tying ourselves to CommonJS this way is a problem. I will let you know once I have something for you to play around with. |
That’s great, thank you! |
Fix at #4621 |
This issue has been resolved via #4621 as part of rollup@3.0.0-5. Note that this is a pre-release, so to test it, you need to install Rollup via |
This issue has been resolved via #4621 as part of rollup@3.0.0-6. Note that this is a pre-release, so to test it, you need to install Rollup via |
This issue has been resolved via #4621 as part of rollup@3.0.0-7. Note that this is a pre-release, so to test it, you need to install Rollup via |
This issue has been resolved via #4621 as part of rollup@3.0.0-8. Note that this is a pre-release, so to test it, you need to install Rollup via |
This issue has been resolved via #4621 as part of rollup@3.0.0. You can test it via |
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
rollup.config.ts gets compiled to ESM and imports
<projdir>/node_modules/@mdx-js/rollup/index.js
as ESMActual Behaviour
rollup.config.ts seems to get compiled to CJS despite
target: ES2020
in the tsconfig.json.The text was updated successfully, but these errors were encountered: