[!] RollupError: Node tried to load your configuration as an ES module even though it is likely CommonJS. To resolve this, change the extension of your configuration to “.cjs” or pass the “–bundleConfigAsCjs” flag.

Sounds familiar?

It took me a while to figure out that the actual error is written lower:

Original error: module is not defined in ES module scope.

What this means is there’s no variable named module in the rollup.config.mjs file.

To fix that, you just need to replace CommonJS export to ES export, which means your module.exports = { should become export default {.

Or, obviously, you could do the opposite. Meaning, rename the config back to rollup.config.js, replace all import statements with const something = require('module-name'), and replace export default with module.exports =.

Did you know that I made an in-browser image converter, where you can convert your images without uploading them anywhere? Try it out and let me know what you think. It's free.

Leave a Comment

Your email address will not be published. Required fields are marked *