This error occurs when React receives a plain object in JSX where it expects a valid component (function or class). This typically happens due to incorrect import/export patterns or defining components as objects instead of functions.
This error is React's way of telling you that you're trying to render something that isn't a valid React component. React components must be functions or classes that return JSX, but instead React received a plain JavaScript object. When you use JSX like <MyComponent />, React expects MyComponent to be either a function component, a class component, or a string (for built-in HTML elements). If MyComponent is a plain object, React can't render it and throws this error. This is a runtime error that appears in the browser console and typically causes your component tree to fail rendering at that point.
Check that your component is defined as a function or class, not as a plain object:
Incorrect (plain object):
// DON'T DO THIS
const MyComponent = {
render: function() {
return <div>Hello</div>;
}
};Correct (function component):
// DO THIS
const MyComponent = () => {
return <div>Hello</div>;
};
// Or this
function MyComponent() {
return <div>Hello</div>;
}Correct (class component):
// Or this
class MyComponent extends React.Component {
render() {
return <div>Hello</div>;
}
}Ensure your import style matches your export style.
If using default export:
// MyComponent.js
export default function MyComponent() {
return <div>Hello</div>;
}
// App.js - correct import
import MyComponent from './MyComponent';If using named export:
// MyComponent.js
export function MyComponent() {
return <div>Hello</div>;
}
// App.js - correct import (note the curly braces)
import { MyComponent } from './MyComponent';Common mistake - mismatched imports:
// MyComponent.js
export default function MyComponent() { /* ... */ }
// App.js - WRONG! This imports the module object
import { MyComponent } from './MyComponent'; // undefined!
// App.js - CORRECT
import MyComponent from './MyComponent';Add a console.log to see what you're actually importing:
import MyComponent from './MyComponent';
console.log('MyComponent is:', MyComponent);
console.log('Type:', typeof MyComponent);
// If it logs an object instead of a function, you have an import/export mismatchYou should see:
- Type: function for function components
- An object with a prototype showing React.Component for class components
If you see a plain object or undefined, your import statement is incorrect.
Make sure you're not accidentally importing the entire module:
Incorrect:
import * as MyComponent from './MyComponent'; // This imports the module object!
<MyComponent /> // Error: object is not a componentCorrect:
import MyComponent from './MyComponent'; // Default import
// OR
import { MyComponent } from './MyComponent'; // Named import
<MyComponent />If you need to use import *, access the component property:
import * as MyModule from './MyComponent';
<MyModule.default /> // If it's a default export
// OR
<MyModule.MyComponent /> // If it's a named exportIf you're using Higher-Order Components (HOCs), ensure you're calling them:
Incorrect:
import { connect } from 'react-redux';
const MyComponent = () => <div>Hello</div>;
// WRONG - connect returns a function, not a component
export default connect;Correct:
import { connect } from 'react-redux';
const MyComponent = () => <div>Hello</div>;
// CORRECT - call the HOC with your component
export default connect(mapStateToProps, mapDispatchToProps)(MyComponent);Circular dependencies can cause imports to be undefined or partial objects:
// ComponentA.js
import ComponentB from './ComponentB';
export default function ComponentA() {
return <ComponentB />;
}
// ComponentB.js
import ComponentA from './ComponentA'; // Circular!
export default function ComponentB() {
return <ComponentA />;
}Solution: Restructure your components to avoid circular imports, or use lazy loading:
import { lazy, Suspense } from 'react';
const ComponentA = lazy(() => import('./ComponentA'));
export default function ComponentB() {
return (
<Suspense fallback={<div>Loading...</div>}>
<ComponentA />
</Suspense>
);
}TypeScript considerations:
In TypeScript projects, this error can occur even when TypeScript shows no type errors. This happens because TypeScript checks types at compile time but doesn't catch runtime import/export mismatches. Always verify your imports match your exports.
Next.js specific issues:
In Next.js, having { "type": "module" } in your package.json can cause module resolution issues. Next.js expects CommonJS modules for server-side rendering. Remove this setting if you encounter this error in Next.js projects.
Module bundler considerations:
Different bundlers (Webpack, Vite, Parcel) may handle imports slightly differently. If you're using barrel exports (index.js files that re-export multiple components), ensure each component is properly exported from the barrel file:
// components/index.js
export { default as Button } from './Button';
export { default as Input } from './Input';
// Not: export default { Button, Input }; // This creates an object!React.createElement vs JSX:
This error can also occur if you're using React.createElement directly:
// Incorrect
React.createElement(myConfigObject, props);
// Correct
React.createElement(MyComponent, props);Prop spreading could cause security issues
Prop spreading could cause security issues
Error: error:0308010C:digital envelope routines::unsupported
Error: error:0308010C:digital envelope routines::unsupported
React Hook "useEffect" is called conditionally. React Hooks must be called in the exact same order in every component render.
React Hook useEffect placed inside a condition
Hook can only be called inside the body of a function component
Hook can only be called inside the body of a function component
Rollup failed to resolve import during build
How to fix "Rollup failed to resolve import" in React