Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Webpack - Error: Module is not a loader (must have normal or pitch function)

My webpack.config.js

var path = require("path")
var webpack = require('webpack')
var BundleTracker = require('webpack-bundle-tracker')

module.exports = {
    context: __dirname,

    entry: [
        'webpack-dev-server/client?http://localhost:3000',
        'webpack/hot/only-dev-server',
        './assets/js/index', // entry point of our app. assets/js/index.js should require other js modules and dependencies it needs
    ],

    output: {
        path: path.resolve('./assets/bundles/'),
        filename: "[name]-[hash].js",
        publicPath: 'http://localhost:3000/assets/bundles/', // Tell django to use this URL to load packages and not use STATIC_URL + bundle_name
    },

    plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoEmitOnErrorsPlugin(), // don't reload if there is an error
        new BundleTracker({filename: './webpack-stats.json'}),
    ],

    module: {
        loaders: [
            {
                test: /\.jsx?$/,
                exclude: /node_modules/,
                loaders: ['react-hot-loader', 'babel-loader?presets[]=react'],
            }, // to transform JSX into JS
        ],
    },

    resolve: {
        modules: ['node_modules', 'bower_components'],
        extensions: ['.js', '.jsx']
    },
} 

Error:

Error: Module 'C:\Workspace\PyCharmProjects\ProjectPearl\node_modules\react-hot-loader\index.js' is not a loader (must have normal or pitch function)

Looks like some got working (https://github.com/webpack/webpack/issues/3180) by adding -loader extension for modules, however for me it still doesn't resolve.

Please assist.

like image 557
theblackpearl Avatar asked Jun 20 '17 04:06

theblackpearl


1 Answers

The usage is react-hot-loader/webpack

loaders: ['react-hot-loader/webpack', 'babel-loader?presets[]=react'],

Look at some example usages here http://gaearon.github.io/react-hot-loader/getstarted/

like image 129
Mukesh Soni Avatar answered Oct 30 '22 17:10

Mukesh Soni