Webpack error with react

后端 未结 2 2473
北海茫月
北海茫月 2021-02-20 16:34

I am trying to configure webpack according to this tutorial and keep getting the same error. I am having trouble debugging these 2 messages:

ERROR in ./app.js
M         


        
相关标签:
2条回答
  • 2021-02-20 17:21

    the loaders option should be nested in a module object like so:

    module.exports = {
      context: __dirname + '/app',
      entry: {
        javascript: "./app.js",
        html: "./index.html"
      },
      output: {
        filename: 'app.js',
        path: __dirname + '/dist'
      },
      module: {
        loaders: [
          {
            test: /\.js$/,
            exclude: /node_modules/,
            loaders: ['babel-loader']
          },
          {
            test: /\.jsx$/,
            loaders: ['babel-loader']
          },
          {
            test: /\.html$/,
            loader: "file?name=[name].[ext]"
          }
        ]
      }
    };
    

    I also added a missing semi-colon at the end ;)

    0 讨论(0)
  • 2021-02-20 17:30

    When I was importing with the syntax

    import Component from './components/component';
    

    I was getting the module parse error. To fix it, I had to specify .jsx and it worked

    import Component from `./components/component.jsx`. 
    

    It wasn't a config error at all. I'm on babel 6 with hot loader.

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