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?
This error happens because npm@3 does not resolve peerDependencies any more.
npm install less less-loader
is the way to go.the error message described the problem well: missing 'less' module.
npm install less --save-dev
will solve it.Most of the time you should have all of less/less-loader/css-loader/style-loader.
npm install style-loader css-loader less-loader less --save-dev
I had the same issue. ERROR in Cannot find module 'less'
I tried as follows:
Then it solved the issues.
@Zhorian yours works awesome, I cannot vote cuz of the low level and neither add comment on your answer! after doing npm install less --save-dev, it works, for the error:
and when you try to install:
It will gave you:
I meet the error also when I have installed less and less-loader both. then I try uninstall them and install them again but not make sense.
Lastly, I find delete the last dist(already exit) can make 'npm run build' right. So, you can try delete the 'dist' dir if it already exits.
It sounds like you haven't installed the
less-loader
into your node_modules. Installing it would fix this.Edit: Also you will get this error when you haven't installed the
css-loader
andstyle-loader
that you are chainingless-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.