Invariant failed: You should not use outside a

后端 未结 20 1428
伪装坚强ぢ
伪装坚强ぢ 2020-12-03 20:55

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:

20条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-03 21:05

    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.

提交回复
热议问题