Parsing error: Identifier 'React' has already been declared
Parsing error: Identifier 'React' has already been declaredShort answer
An import binds its name in the file's scope, and no other declaration there may use the same name. So React is declared twice: two imports, or an import next to a const or require. Keep one. With the automatic JSX runtime you may not need the React import at all, and a codemod removes it.
Fix it fast
1Find out which cause you have
List every line in the failing file that binds the name React.
grep -nE "import React|import \* as React|const React|let React|var React|require\('react'\)" path/to/File.jsx2Match what you see, then jump to its fix
- 1
The grep shows two lines, for example import React from 'react' and later import React, { useState } from 'react'React is imported or declared twice in one fileFix - 2
The project uses React 17 or newer with an automatic JSX runtime, and files import React only for JSXThe import is left over from the old JSX transformFix
- 1
What does the error look like?
Parsing error: Identifier 'React' has already been declaredSyntaxError: Identifier 'React' has already been declared
Cause 1 of 2
React is imported or declared twice in one file
1Check
MDN says an imported binding cannot be in the same scope as any other declaration, including let, const, class, function, var and another import.
grep -n "from 'react'" path/to/File.jsx2Fix
Merge the lines into one import that carries every name you need.
// before
import React from 'react';
import React, { useState } from 'react';
// after
import React, { useState } from 'react';3Verify
The parser stops reporting the error.
npx eslint path/to/File.jsxConfirmed by developer.mozilla.org
Cause 2 of 2
The import is left over from the old JSX transform
1Check
The React team says the new transform imports what JSX needs by itself, so JSX no longer requires import React. Babel's automatic runtime does the same, while the classic runtime imports nothing and uses React.createElement.
grep -rn "runtime" babel.config.* .babelrc tsconfig.json vite.config.*2Fix
Run the codemod that removes unused React imports and converts the rest to named imports, then keep only the named hooks you use.
npx react-codemod update-react-imports3Verify
Run the app or build; JSX still compiles and the duplicate is gone.
npm run buildConfirmed by legacy.reactjs.org
How do I stop it coming back?
- Let the editor remove unused imports on save, so duplicates do not pile up after a merge.
- Set the JSX runtime to automatic in new projects.
- Turn off react/react-in-jsx-scope and react/jsx-uses-react in ESLint when you use the automatic runtime.
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
Cannot find module react/jsx-runtime in a React build
Uncaught Error: Cannot find module 'react/jsx-runtime'
react/jsx-runtime is the file the new JSX transform imports for you.
3 causes, each with a fixWeb 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 fix