Webpack error in Cannot find module 'less'

I try to use less bootloader in webpack, and the problem is I installed less bootloader locally, but when I try to compile everything using the webpack command in bask, it prints: "ERROR in Can not find module 'Less''. At my entry point, I less files 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 business and how should I fix it?

+19
less webpack
source share
7 answers

It looks like you did not install less-loader in your node_modules. Installing this will fix it.

 npm install less-loader --save-dev 

Edit: this error also appears if you have not installed css-loader and style-loader to which you are connecting less-loader .

Anyone who encounters this can get a plus on the issue I presented for a bad post. "Error in Cannot find module" Less "" if missing bootloaders are chained after Less. Correct the error message .

+19
source share

This error occurs because npm @ 3 no longer resolves peerDependencies.

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

+54
source share

I had the same problem. ERROR in Unable to find less module

 β”œβ”€β”€ UNMET PEER DEPENDENCY file-loader@ * β”œβ”€β”€ UNMET PEER DEPENDENCY less@ ^2.3.1 β”œβ”€β”€ webpack@1.13.2 └── webpack-dev-server@1.16.2 npm WARN EPEERINVALID less-loader@2.2.3 requires a peer of less@ ^2.3.1 but none was installed. npm WARN EPEERINVALID url-loader@0.5.7 requires a peer of file-loader@ * but none was installed. 

I tried to do the following:

 npm install --save-dev less npm install --save-dev file-loader 

Then he solved the problem.

+15
source share

I had the same problem with a .Net Core project. I solved this by adding less to my package.json file as well as to the smaller bootloader.

 "less-loader": "2.2.3", "less": "2.7.2" 
+5
source share

In my case, I already had less-loader, style-loader and css-loader , but it gave the same error. When I installed less, then this is fixed. So make sure you install less too. npm install less --save-dev fixed my problem.

+5
source share

@Zhorian your work is amazing, I can’t vote for the low level and do not comment on your answer! after running npm install less --save-dev, it works, for the error:

 Module build failed: Error: Cannot find module 'less' 

and when trying to install:

 npm install less-loader style-loader css-loader --save-dev 

This will give you:

 β”œβ”€β”€ css-loader@0.26.1 β”œβ”€β”€ UNMET PEER DEPENDENCY less@ ^2.3.1 β”œβ”€β”€ less-loader@2.2.3 └── style-loader@0.13.1 
0
source share

the error message describes the problem well: the 'less' module is missing.

npm install less --save-dev will solve this.

In most cases, you should have all the less / less-loader / css-loader / style-loader files.

npm install style-loader css-loader less-loader less --save-dev

0
source share

All Articles