I use react-router-dom for routing in my React application. Part of my app extracted in another package. List of dependencies looks like this:
I solved this cryptic error by deleting the dependency of 'react-router-dom' from MyComponent. I deleted 'node_modules/react-router-dom' and from 'package.json' My App is structured as follows:
AppFolder
├── README.md
├── build
├── node_modules
│ ├── react-router-dom
├── package-lock.json
├── package.json
├── public
│ ├── favicon.ico
│ ├── index.html
│ └── manifest.json
└── src
├── App.css
├── App.js
├── App.test.js
├── index.js
├── redux
│ ├── reducers.js
│ └── store.js
└── serviceWorker.js
MyComponent
├── README.md
├── dist
├── node_modules
│ ├── react-router-dom
├── package-lock.json
├── package.json
├── rollup.config.js
└── src
├── index.js
├── styles.css
└── test.js
This is the source code for App.js
import MyComponent from 'MyComponent'
export default App(){
return (
)
}
This is the export for MyComponent
export default withRouter(MyComponent);
If 'react-router-dom' is left in the component folder, then the error appears.