Webpack - Error: Cannot define 'query' and multiple loaders in loaders list

前端 未结 6 707
梦谈多话
梦谈多话 2021-01-30 16:28

This error appeared after I added the react-hot loader in an array following this tutorial: https://thoughtbot.com/blog/setting-up-webpack-for-react-and-hot-module-

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-30 17:22

    It seems that the query is an alternative way of customizing the behaviour of a single loader, that is cleaner than specifying those parameters inline (see below). If multiple loaders are present, Webpack does not know to which the query configuration applies.

    The following should solve your problem:

    module: {
        loaders: [{
            test: /\.jsx?$/,
            exclude: /node_modules/,
            loaders: ['react-hot', 'babel?presets[]=es2015,presets[]=stage-0,presets[]=react,plugins[]=transform-runtime']
        }
    

    EDIT: While this solution works for Webpack 1, see the other answers for cleaner solutions that work in more recent versions.

提交回复
热议问题