Rollup - react.js does not export Component
See original GitHub issueI’m trying to use react-redux in a project that’s bundled with Rollup. Unfortunately I’m getting repeated errors about:
react/react.js does not export Component (imported by react-redux/es/components/Provider.js)
The following changes to Provider.js
fix my issues (all tests passing):
diff --git a/src/components/Provider.js b/src/components/Provider.js
index db39187..030517c 100644
--- a/src/components/Provider.js
+++ b/src/components/Provider.js
@@ -1,4 +1,4 @@
-import { Component, PropTypes, Children } from 'react'
+import * as React from 'react'
import { storeShape, subscriptionShape } from '../utils/PropTypes'
import warning from '../utils/warning'
@@ -18,7 +18,7 @@ function warnAboutReceivingStore() {
)
}
-export default class Provider extends Component {
+export default class Provider extends React.Component {
getChildContext() {
return { store: this.store, storeSubscription: null }
}
@@ -29,7 +29,7 @@ export default class Provider extends Component {
}
render() {
- return Children.only(this.props.children)
+ return React.Children.only(this.props.children)
}
}
@@ -46,7 +46,7 @@ if (process.env.NODE_ENV !== 'production') {
Provider.propTypes = {
store: storeShape.isRequired,
- children: PropTypes.element.isRequired
+ children: React.PropTypes.element.isRequired
}
Provider.childContextTypes = {
store: storeShape.isRequired,
However this has the side effect of adding
var React = _interopRequireWildcard(_react);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
to both dist/react-redux.js
and lib/components/Provider.js
I’m conscious of this having implications which I’m not aware of, so looking for any advice on resolving this issue, either within a Rollup plugin or otherwise.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Rollup.js can not detect default exports when trying to build ...
Rollup.js can not detect default exports when trying to build component library with React.js ; from 'rollup-plugin-babel'; ; from '@rollup/plugin ...
Read more >Rollup.js - SVGR
SVGR provides an official rollup.js plugin to import SVG as React components. ... export if there is no other plugin handling svg files...
Read more >How to Bundle JavaScript With Rollup — Step-by-Step Tutorial
Rollup is a next-generation JavaScript module bundler. Author your app or library using ES2015 modules, then efficiently bundle them up into a single...
Read more >How to support subpath imports using React+Rollup+Typescript
In each index.ts , export all the necessary components of the main component. Name each folder the appropriate name for the component as...
Read more >Code-Splitting - React
Code-Splitting is a feature supported by bundlers like Webpack, Rollup and ... resolves to a module with a default export containing a React...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For anyone else following after, the solution here was to use rollup-plugin-commonjs with the following configuration:
The
namedExports
section allows the plugin to correctly find the “named” exports from the React object.See docs for more details: https://github.com/rollup/rollup-plugin-commonjs#custom-named-exports
For React
v#16.2.0
the lib file name is slightly different (react.js
->index.js
)