Importing/exporting the Express router using ES6 import + export keywords and Babel

后端 未结 2 731
粉色の甜心
粉色の甜心 2021-02-07 08:07

I have an old test project originally built with Express 2.X. I am moving it to Express 4.x and trying to insert Babel 6.x to experiment with ES6 features server-side.

T

相关标签:
2条回答
  • 2021-02-07 08:10

    Try this:

    export default router;
    
    0 讨论(0)
  • 2021-02-07 08:26

    The problem is that you are exporting router as named export router, but trying to import it as indexRoute.

    You should either rename your export:

    export { router as indexRoute }
    

    or change your import:

    import { router as indexRoute } from './routes/index_route';
    
    0 讨论(0)
提交回复
热议问题