You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
constlib=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
The text was updated successfully, but these errors were encountered:
kishor82
changed the title
Rollup configuration with ESM
Question: Rollup configuration with ESM
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:
The problem is occurring on this line in
rollup.config.js
:The solution is to use
import
instead ofrequire
. 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
Additional context/Screenshots
No response
The text was updated successfully, but these errors were encountered: