Skip to content
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

Question: Rollup configuration with ESM #6364

Open
kishor82 opened this issue Apr 21, 2024 · 0 comments
Open

Question: Rollup configuration with ESM #6364

kishor82 opened this issue Apr 21, 2024 · 0 comments

Comments

@kishor82
Copy link

kishor82 commented Apr 21, 2024

Describe the issue

I'm currently setting up Rollup with a configuration similar to Axios, where the package.json specifies "type": "module". During the build process, I encountered the following issue:

> rollup -c -m

[!] 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.

Original error: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/Users/kishorrathva/Workspace/dev/flatten-this-json/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.

The problem is occurring on this line in rollup.config.js:

const lib = require("./package.json");

The solution is to use import instead of require. I'm curious how the build is working for Axios with a similar setup.

Thanks for your help!

Example Code

No response

Expected behavior

No response

Axios Version

1.6.0

Adapter Version

No response

Browser

No response

Browser Version

No response

Node.js Version

v20.9.0

OS

OSX 14.4.1

Additional Library Versions

rollup  ^4.15.0

Additional context/Screenshots

No response

@kishor82 kishor82 changed the title Rollup configuration with ESM Question: Rollup configuration with ESM Apr 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant