Build failed when use react-router-dom and path-to-regexp
See original GitHub issueDescribe the bug
use react-router-dom
and path-to-regexp
package in the same time comes a problem
import {
BrowserRouter as Router,
Switch,
Route,
useParams
} from "react-router-dom";
import { match } from 'path-to-regexp' // change to 'path-to-regexp/dist.es2015' works
console.log(match)
Got error like this
I do prepare a codesandbox link, but it’s works fine.
I can’t make it right on my local environment.
Reproduction
try download this codesandbox demo and run npm run dev
System Info
Output of npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers
:
System:
OS: macOS 10.15.6
CPU: (8) x64 Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
Memory: 58.64 MB / 8.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 14.16.1 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.12 - /usr/local/bin/npm
Browsers:
Chrome: 89.0.4389.114
Firefox: 86.0
Safari: 13.1.2
Safari Technology Preview: 14.0
npmPackages:
vite: 2.1.2 => 2.1.2
Used package manager: npm / yarn
Logs
> node_modules/react-router/esm/react-router.js:9:7: error: No matching export in "node_modules/path-to-regexp/dist.es2015/index.js" for import "default"
9 │ import pathToRegexp from 'path-to-regexp';
╵ ~~~~~~~~~~~~
Before submitting the issue, please make sure you do the following
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Provide a description in this issue that describes the bug.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:10 (3 by maintainers)
Top Results From Across the Web
4 - Stack Overflow
I solved it by installing react-router . My react-router-dom 's version is 4.2.2. npm install --save 'react-router'.
Read more >reactjs/react-router - Gitter
I'm stuck at the very beginning with the error: ./node_modules/react-router-dom/node_modules/react/react.js Module build failed: Error: ENOENT: no such file ...
Read more >generatePath - React Router: Declarative Routing for React.js
The generatePath function can be used to generate URLs to the routes. Internally the path-to-regexp library is used. import { generatePath } from...
Read more >Tutorial v6.6.1 - React Router
Welcome to the tutorial! We'll be building a small, but feature-rich app that lets you keep track of your contacts. We expect it...
Read more >Route render prop - React Router v5
The Route component is perhaps the most important component in React Router to understand and learn to use well. Its most basic responsibility...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@seanaye I solved it by using
"history": "^4.10.1"
sincereact-router-dom
uses this old version of history.https://github.com/ReactTraining/react-router/blob/fc91700e08df8147bd2bb1be19a299cbb14dbcaa/packages/react-router-dom/package.json#L44
This issue is that vite cannot tell which version of history to use during the dev run and tries using the latest one (5.0.0). So remove/downgrade that in your package.json
Hope this helps
Caraca man… you saved my day… Thanks a lot…