2

I am trying to deploy the React project via Github CI/CD to Azure Static WebApp. However, Github throws build error non visible on my local installation. I have tried yarn run build and yarn run locally without any issue, but the Github keep complaining with the following error Module '"react-router"' has no exported member 'PartialRouteObject'. TS2305 on the line:

import { PartialRouteObject } from 'react-router';

The package.js has this reference "react-router-dom": "6.0.0-beta.0", Any idea how to fix this?

Jim
  • 2,760
  • 8
  • 42
  • 66

2 Answers2

1

I had same issue when I upgraded react-router-dom to version 6. I fixed this issue by replacing PartialRouteObject with RouteObject.

import { RouteObject } from 'react-router';
Abhiram P Jayan
  • 339
  • 5
  • 16
0

I encountered the same problem with "react-router-dom": "6.0.0-beta.0" and after researching, I found the hint in node_modules/react-router/README.md.

If you're using React Router, you should never `import` anything directly from
the `react-router` package, but you should have everything you need in either
`react-router-dom` or `react-router-native`. Both of those packages re-export
everything from `react-router`.

If you'd like to extend React Router and you know what you're doing, you should
add `react-router` **as a peer dependency, not a regular dependency** in your
package.

thus I did add to package.json

  "peerDependencies": {
    "react-router": "6.0.0-beta.0"
  },

and run npm i from the terminal to make the change effective.

You may also need to disable eslint as it still complains in my case and fail the CI/CD pipeline.

// eslint-disable-next-line import/named
import {PartialRouteObject} from 'react-router'

At the time of writing, it's worth noting that you may upgrade to the latest version of react-router v6.3 and get away with this issue. But in our case, we can't since there are a few features working in v6.0.0-beta.0 that v6.3 can't still deliver, such as https://github.com/remix-run/react-router/issues/8139

Hope it helps. Happy coding!

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
tinutmap
  • 1
  • 1