ERROR in ./src/webpack_01.less (../node_modules/css-loader/dist/cjs.js!../node_modules/less-loader/

When webpack was packaging, the following error occurred:

ERROR in ./src/webpack_01.less (…/node_modules/css-loader/dist/cjs.js!../node_modules/less-loader/dist/cjs.js!./src/webpack_01.less)
Module build failed (from …/node_modules/less-loader/dist/cjs.js):
Error: Cannot find module ‘less’

Checked other people's solutions, the main reasons for the error are:

  1. The order of the loader configuration files is wrong, the correct order is

{
test: /.less$/,
use: [
‘style-loader’,
‘css-loader’,
‘less-loader’
]
},

  1. The download of the package is not complete, you should download the several loaders used above,
npm i -s style-loader css-loader less-loader

The less-loader depends on less for normal operation. If the lesspackage has not been downloaded in the project, the above problems will also occur (I also have the problem here), so you also need to download the less package. The complete download package command is:

npm i -s style-loader css-loader less-loader less

Guess you like

Origin blog.csdn.net/chen__cheng/article/details/115195502