webpack error in Cannot find module 'less'

Alex Buddy picture Alex Buddy · Apr 21, 2016 · Viewed 39.9k times · Source

I'm trying to use less loader in webpack and the issues is - I've installed less loader locally, but when I try to compile everything using webpack command in bask, it prints out: "ERROR in Cannot find module 'less'". In my entry point I require some less file like

require("./less_components/style.less");

Here is my webpack.config file

module.exports = {

entry: "./entry.js",

output: {

    path: "./build",

    filename: "./bundle.js"

},

module: {

    loaders: [

        {test: /\.js$/, exlude: /node_modules/, loader: "babel-loader"},

        {test: /\.less$/, loader: "style!css!less"}

    ]
}
}

What's the matter and how I should fix it?

Answer

Dom Sun picture Dom Sun · Apr 3, 2017

This error happens because npm@3 does not resolve peerDependencies any more.

npm install less less-loader is the way to go.