Link cannot be imported from react-router
export 'Link' (imported as 'Link') was not found in 'react-router'Short answer
Which package exports Link depends on your React Router major version. In v5 and v6, Link lives in react-router-dom, not react-router. In v7 and v8, Link is imported from react-router. The error means your import and your installed version disagree, so print the version and match the two.
Fix it fast
1Find out which cause you have
List the installed React Router packages. The major version decides which import line is correct.
npm ls react-router react-router-dom2Match what you see, then jump to its fix
- 1
npm ls shows react-router 5.x or 6.x, and the failing line is import { Link } from 'react-router'You are on v5 or v6 and import Link from react-routerFix - 2
Your imports say from 'react-router' (as in the v7 docs) while npm ls shows 6.xCode was written for v7 but react-router is still on v6Fix - 3
Import from 'react-router-dom' fails after upgrading, or the package is missingYou left react-router-dom behind while moving to v8Fix
- 1
What does the error look like?
export 'Link' (imported as 'Link') was not found in 'react-router''react-router' does not contain an export named 'Link'
Cause 1 of 3
You are on v5 or v6 and import Link from react-router
1Check
Search for imports of the core package. In the v6 upgrade guide, the web components such as Link and BrowserRouter are imported from react-router-dom.
grep -rn "from ['\"]react-router['\"]" src/2Fix
Install the web package if it is missing and import the web components from it.
npm install react-router-dom@6
// before
import { Link } from "react-router";
// after
import { Link, BrowserRouter } from "react-router-dom";3Verify
Restart the dev server. The build no longer reports a missing export.
npm run buildConfirmed by reactrouter.com
Cause 2 of 3
Code was written for v7 but react-router is still on v6
1Check
The v7 upgrade page imports Link and useLocation from react-router. If package.json still pins an older major, that import has nothing to find.
grep -n "react-router" package.json2Fix
Move to a current release, then keep the imports from react-router. The upgrade page gives this command for v7 and says to update to the latest v7 first.
npm install react-router@7
// import { Link, useLocation } from "react-router";3Verify
Check that one react-router version is installed and the app builds.
npm ls react-router
npm run buildConfirmed by reactrouter.com
Cause 3 of 3
You left react-router-dom behind while moving to v8
1Check
The v7 upgrade page says v8 removes the react-router-dom re-export package. Look for leftover imports and for the dependency.
grep -rn "react-router-dom" src/ package.json2Fix
Uninstall react-router-dom, import everything from react-router, and import DOM-specific APIs such as RouterProvider from react-router/dom.
npm uninstall react-router-dom
import { Link, useLocation } from "react-router";
import { RouterProvider } from "react-router/dom";3Verify
Search again: no file should import react-router-dom.
grep -rn "react-router-dom" src/ || echo "none left"Confirmed by reactrouter.com
How do I stop it coming back?
- Read the docs version selector before copying an import line: the right package name changed between v6 and v7.
- Keep one React Router package family in package.json, not react-router and react-router-dom at different majors.
- Run the build in CI so a bad import fails before deploy.
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.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
Switch, Redirect or useHistory missing after a React Router upgrade
Attempted import error: 'useHistory' is not exported from 'react-router-dom'
React Router v6 removed Switch.
3 causes, each with a fixWeb apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Astro Code component fails inside a React component
Astro components cannot be rendered directly via function call
Astro components such as Code only exist on the server and render static HTML.
2 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
How to catch and handle a 422 from Axios in a Redux thunk
action.error.message is 'Rejected' and action.payload is undefined
A 422 means the server read the request but cannot process its content, so repeating it unchanged fails again.
4 causes, each with a fixWeb apps
axios gets 429 Too Many Requests from a React app
429 (Too Many Requests)
A 429 comes from the server or an API gateway, not from axios: your client sent too many requests in a window.
4 causes, each with a fix