Expected
I should be able to export my App component file and import it into my index.js.
Results
I get the following error
React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object
My index.js
const React = require('react');
const ReactDOM = require('react-dom');
const App = require('./components/App');
require('./index.css');
ReactDOM.render(
<App />,
document.getElementById('app')
);
Then in my components/App.js
const React = require('react');
export default class App extends React.Component {
render() {
return (
<div>
Hell World! Wasabi Sauce!
</div>
);
}
}
// module.exports = App;
If I uncomment module.exports = App; it will work, but I'm trying to use the export syntax. What is driving me nuts is in another project I am doing the exact same thing here and it's working fine :(
import/exportsyntax is reserved for the ES6 modules. When using CommonJS modules, just usemodule.exports. - Przemysław Zalewskiconsole.log(require('./components/App'))to see what gets exported? - Przemysław ZalewskiObject {__esModule: true, default: function}anddefault.nameisApp. My path is correct because the commonJS way, module.exports works. - Leon Gabanconst App = require('./components/App').defaultin order to get the component (default export). - Przemysław Zalewski