Rollup cannot find a default export in React's CommonJS entry file
Your error
"default" is not exported by "node_modules/react/index.js", imported by "src/App.js".2 more lines it can showFix it fast
Most common cause, 1 of 3No CommonJS plugin translates React's entry
Install the scoped plugins, remove the old one if it is still listed, and add both to the config. node-resolve finds the package in node_modules; commonjs turns its CommonJS code into something Rollup can bundle.
npm uninstall rollup-plugin-commonjs
npm install --save-dev @rollup/plugin-commonjs @rollup/plugin-node-resolve
// rollup.config.mjs
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
export default {
input: 'src/main.js',
output: { file: 'dist/bundle.js', format: 'es' },
plugins: [commonjs(), resolve()],
};Short answer
Rollup 4 reports "default" is not exported by "node_modules/react/index.js" (Rollup 2 printed 'default' in single quotes) because React 19 still publishes that entry as CommonJS, while Rollup reads only ES module syntax by itself. Add @rollup/plugin-commonjs beside @rollup/plugin-node-resolve, keep node_modules inside its include, or mark react as external in a component library.
Which cause do you have?
Print the plugins and the external list from your Rollup config, then the versions of Rollup and its two module plugins. A config with no commonjs entry, or one that still loads the old rollup-plugin-commonjs package, already accounts for the error.
grep -n "commonjs\|resolve\|external\|include" rollup.config.*
npm ls rollup @rollup/plugin-commonjs @rollup/plugin-node-resolve rollup-plugin-commonjsThen find the line you see in this list and open its fix:
- 1No CommonJS plugin translates React's entry
The plugins array has no commonjs() call, or the import comes from the deprecated rollup-plugin-commonjs - 2The commonjs include pattern leaves React out
commonjs() is in the config, but with an include list such as 'src/**' or a node_modules/** glob in a monorepo - 3A component library bundles React instead of leaving it external
The bundle is a package for other apps, react is a peer dependency, and the config has no external list
What does the error look like?
"default" is not exported by "node_modules/react/index.js", imported by "src/App.js".'default' is not exported by node_modules/react/index.js, imported by src/App.js"useState" is not exported by "node_modules/react/index.js", imported by "src/Counter.js".
Cause 1 of 3
No CommonJS plugin translates React's entry
You seeThe plugins array has no commonjs() call, or the import comes from the deprecated rollup-plugin-commonjs
Check
Rollup says default is not exported by node_modules/react/index.js when nothing converts that file: it fills module.exports with a require call and has no export statement, and Rollup only understands ES module syntax unless a plugin translates the rest. Rollup's troubleshooting guide sends you to @rollup/plugin-commonjs, which detects the named exports on its own, in place of the deprecated rollup-plugin-commonjs.
head -n 8 node_modules/react/index.jsFix
Install the scoped plugins, remove the old one if it is still listed, and add both to the config. node-resolve finds the package in node_modules; commonjs turns its CommonJS code into something Rollup can bundle.
npm uninstall rollup-plugin-commonjs
npm install --save-dev @rollup/plugin-commonjs @rollup/plugin-node-resolve
// rollup.config.mjs
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
export default {
input: 'src/main.js',
output: { file: 'dist/bundle.js', format: 'es' },
plugins: [commonjs(), resolve()],
};Verify
The build finishes, writes dist/bundle.js and no longer prints the not-exported message for react.
npx rollup -cConfirmed by rollupjs.org
Cause 2 of 3
The commonjs include pattern leaves React out
You seecommonjs() is in the config, but with an include list such as 'src/**' or a node_modules/** glob in a monorepo
Check
The same not-exported message can appear with the plugin installed when its include option is narrowed. Left unset, include covers every .js and .cjs file; a list of patterns restricts the plugin to what matches, so node_modules/react/index.js passes through untranslated. In a monorepo or after npm link, the real path of the React copy can also sit outside the local node_modules folder that a glob names.
grep -n -A3 "commonjs(" rollup.config.*Fix
Delete the include option, or use the regular expression that the plugin's README suggests, which matches a node_modules folder wherever it is.
commonjs({
include: /node_modules/,
}),Verify
Run the build again; the bundle now contains React's code, or the import is gone if react is external.
npx rollup -cConfirmed by github.com
Cause 3 of 3
A component library bundles React instead of leaving it external
You seeThe bundle is a package for other apps, react is a peer dependency, and the config has no external list
Check
When the build is a component library, the not-exported error for react/index.js shows that React is being pulled into your package at all. The app that installs the library supplies its own React. Ids in Rollup's external option stay outside the bundle, so the import is kept as written and React's CommonJS file is never read.
grep -n -A4 "peerDependencies" package.jsonFix
List React and its subpath imports as external. The plugins can stay for any other CommonJS dependency.
// rollup.config.mjs
export default {
input: 'src/index.js',
output: { file: 'dist/index.js', format: 'es' },
external: ['react', 'react-dom', 'react/jsx-runtime'],
plugins: [commonjs(), resolve()],
};Verify
The output keeps a plain import from react and holds none of React's own source.
grep -n "from 'react'" dist/index.jsConfirmed by rollupjs.org
How do I stop it coming back?
- Start every Rollup config that touches npm packages with @rollup/plugin-node-resolve and @rollup/plugin-commonjs, and pin both in devDependencies.
- In library packages keep react and react-dom in peerDependencies and in external together, so the two lists cannot drift apart.
- Run the Rollup build in CI on every dependency upgrade; a missing export stops it with the error code MISSING_EXPORT before a broken bundle ships.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: TaxiDex, QistLock, Taskvare.