我正在尝试在webpack中使用较少的加载器,问题是 - 我在本地安装了较少的加载器,但是当我尝试使用webpack命令在bask中编译所有内容时,它打印出:“找不到模块中的错误”减'”。在我的入口点,我需要一些较少的文件,如
require("./less_components/style.less");
这是我的webpack.config文件
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"}
]
}
}
问题是什么以及我应该如何解决?
答案 0 :(得分:49)
发生此错误是因为npm @ 3不再解析peerDependencies。
npm install less less-loader
是要走的路。
答案 1 :(得分:18)
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. https://github.com/webpack/less-loader/issues/89
答案 2 :(得分:15)
我有同样的问题。 ERROR in找不到模块'less'
├── 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.
我尝试如下:
npm install --save-dev less
npm install --save-dev file-loader
然后它解决了问题。
答案 3 :(得分:4)
我在.Net Core项目中遇到了同样的问题。我通过向package.json文件添加less以及less-loader来解决这个问题。
"less-loader": "2.2.3",
"less": "2.7.2"
答案 4 :(得分:4)
就我而言,我已经有labels = ['label1', 'label2', 'label3']
num = 5
repeated = []
for i in labels:
repeated.extend([i]*num)
了,但它仍给出相同的错误。当我安装较少时,它就固定了。因此,请确保也减少安装。
less-loader, style-loader and css-loader
解决了我的问题。
答案 5 :(得分:0)
Module build failed: Error: Cannot find module 'less'
当您尝试安装时:
npm install less-loader style-loader css-loader --save-dev
它会给你:
├── css-loader@0.26.1
├── UNMET PEER DEPENDENCY less@^2.3.1
├── less-loader@2.2.3
└── style-loader@0.13.1
答案 6 :(得分:0)
错误消息很好地说明了问题:缺少“较少”模块。
Request
将解决它。
大多数时候,您应该拥有less / less-loader / css-loader / style-loader。
npm install less --save-dev
答案 7 :(得分:0)