使用npm安装less,指定版本为5
npm install --save less less-loader@5
报错
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: app@0.1.0
npm ERR! Found: less@4.1.2
npm ERR! node_modules/less
npm ERR! less@"^4.1.2" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer less@"^2.3.1 || ^3.0.0" from less-loader@5.0.0
npm ERR! node_modules/less-loader
npm ERR! dev less-loader@"5" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
百度了很多解决方法,都说是版本过低过高问题,一直以为自己是版本过高,后来一直在安装低版本的less,一直报同样的错误。
在项目文件夹里找到package.lock.json文件,里面查看到less的版本是4.1.2,然后想到了查一下所有版本。
分别用指令
npm view less-loader versions
npm view less versions
查了less-loader和less的版本,才发现是less-loader的版本太低了。
最后没有指定版本,直接使用下面的指令,默认安装的最新版本。
npm install less-loader