import syntax not working with webpack

前端 未结 2 1612
醉话见心
醉话见心 2021-01-04 06:00

I got Illegal import declaration error. when I tried to integrated a react js repo with webpack

I migrated the original source code from https://githu

相关标签:
2条回答
  • 2021-01-04 06:19

    Use Babel via babel-loader to transform import declarations (and other ES2015 if you want). http://babeljs.io/docs/setup/#webpack

    0 讨论(0)
  • 2021-01-04 06:28

    As @JMM answered, it seems you need babel-loader. in addition, I was still facing the same problem, and finally get resolved by editing webpack.config.js such like

       module: {
         loaders: [
    -      {test: /\.jsx?$/, loader: 'babel-loader'},
    -      {test: /\.jsx$/, loader: 'jsx-loader'}
    +      {test: /\.jsx$/, loader: 'jsx-loader'},
    +      {test: /\.jsx?$/, loader: 'babel-loader'}
         ]
       },
    

    or because jsx-loader looks no longer working with this config, it can be deleted.

    I hope it would help

    0 讨论(0)
提交回复
热议问题