Minified React error 130 in a production build
Minified React error #130Short answer
Error 130 is React's message that an element type is invalid: it expected a string or a component but got something else, often undefined. The cause is most often an import that does not match its export, or a lazy import without a default export. Match the import style to the export.
Fix it fast
1Find out which cause you have
Find which component receives undefined. Run the development build, where React prints the full message and a component stack, then check what each import resolves to.
npm run dev2Match what you see, then jump to its fix
- 1
The full development message names the bad value, often undefined; it appears right after you added or renamed an importA default import for a named export, or the reverseFix - 2
The failure appears only when the lazy component first renders, and the file has a named export onlyReact.lazy points at a module without a default exportFix
- 1
What does the error look like?
Minified React error #130Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got:
Cause 1 of 2
A default import for a named export, or the reverse
1Check
A default export is imported without braces and a named export with braces. Using the wrong one gives you undefined, and React then has nothing to render. Print what the import really is.
import * as Mod from './Button';
console.log(Object.keys(Mod)); // is the component under 'default' or a name?2Fix
Use the import form that matches the export.
// Button.js has: export default function Button() {}
import Button from './Button';
// Button.js has: export function Button() {}
import { Button } from './Button';3Verify
Rebuild and load the page that failed; the component renders.
npm run build && npm run previewConfirmed by react.dev
Cause 2 of 2
React.lazy points at a module without a default export
1Check
The function you give to lazy must resolve to an object whose default property is the component. A module with only named exports has no default.
grep -n "export" src/components/Chart.js2Fix
Add a default export, or map the named export to default inside the lazy call.
const Chart = lazy(() =>
import('./Chart.js').then(m => ({ default: m.Chart }))
);3Verify
Render the lazy component inside Suspense and confirm it loads.
npm run build && npm run previewConfirmed by react.dev
How do I stop it coming back?
- Pick one export style per project (named or default) and keep to it.
- Run the production build in CI and open one page, so a minified error appears before release.
- Give each component a file name equal to its export name.
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 built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Web apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Can't resolve '../axios' in a React project
Module not found: Error: Can't resolve '../axios'
A path that starts with ./ or ../ is a file path, not the axios package.
3 causes, each with a fixWeb apps
Axios returns 401 from a React app but the login works elsewhere
Error: Request failed with status code 401
A 401 means the server received the request without valid credentials.
3 causes, each with a fixWeb apps
An axios call never finishes when the API server stops answering
code: 'ECONNABORTED'
Axios has no timeout unless you give it one: the default is 0, which means wait forever.
3 causes, each with a fix