Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webpack error in Cannot find module 'less'

Tags:

webpack

less

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?

like image 975
Alex Buddy Avatar asked Apr 21 '16 21:04

Alex Buddy


Video Answer


2 Answers

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

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

like image 170
Dom Sun Avatar answered Oct 09 '22 18:10

Dom Sun


It sounds like you haven't installed the less-loader into your node_modules. Installing it would fix this.

npm install less-loader --save-dev 

Edit: Also you will get this error when you haven't installed the css-loader and style-loader that you are chaining less-loader to.

Anyone who comes across this can plus on the issue I submitted for the bad message. "Error in Cannot find module 'less'" when missing loaders chained after less. Revise error message.

like image 33
Sean Larkin Avatar answered Oct 09 '22 17:10

Sean Larkin