webpack处理less的loader_登录器和引擎版本号不匹配

webpack处理less的loader_登录器和引擎版本号不匹配Theremightbeaproblemwiththeprojectdependencytree.ItislikelynotabuginCreateReactApp,butsomethingyouneedtofixlocally.Thereact-scriptspackageprovidedbyCreateReactApprequiresadependency:”webpack”:”4.44.2″Don’ttryt

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.

The react-scripts package provided by Create React App requires a dependency:

  "webpack": "4.44.2"

Don't try to install it manually: your package manager does it automatically.
However, a different version of webpack was detected higher up in the tree:

  D:\Web\Project\RenHai1_admin-1\renhai_admin\node_modules\webpack (version: 5.64.2)

Manually installing incompatible versions is known to cause hard-to-debug issues.

If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.

To fix the dependency tree, try following the steps below in the exact order:

  1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
  2. Delete node_modules in your project folder.
  3. Remove "webpack" from dependencies and/or devDependencies in the package.json file in your project folder.
  4. Run npm install or yarn, depending on the package manager you use.

In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:

  5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
     This may help because npm has known issues with package hoisting which may get resolved in future versions.

  6. Check if D:\Web\Project\RenHai1_admin-1\renhai_admin\node_modules\webpack is outside your project directory.
     For example, you might have accidentally installed something in your home folder.

  7. Try running npm ls webpack in your project folder.
     This will tell you which other package (apart from the expected react-scripts) installed webpack.

If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.

P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!

昨天遇到这样一个问题 按照上面的方法都试了一下 仍然解决不了

 - Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
 - Delete node_modules in your project folder.
 - Remove "webpack" from dependencies and/or devDependencies in the package.json file in your project folder.
 - Run npm install or yarn, depending on the package manager you use.

首先第一种

在第三步的时候我并没有在package.json中找到webpack配置项,就跳过继续第四步,结果没解决

  • 指定版本号下载
  • 指定版本号全局卸载再下载

都不能解决

接着就注意到是不是npm inpm i -s的原因,用npm i -s重复上面的操作 仍然不行
主要还是没有成功配置上在package.json中没有webpack配置项,具体什么原因我也不清楚
其中还出现了下面这个问题

internal/modules/cjs/loader.js:888
  throw err;
  ^

Error: Cannot find module 'webpack/lib/node/NodeTemplatePlugin'
Require stack:
- D:\Web\Project\RenHai1_admin-1\renhai_admin\node_modules\html-webpack-plugin\lib\child-compiler.js
- D:\Web\Project\RenHai1_admin-1\renhai_admin\node_modules\html-webpack-plugin\lib\cached-child-compiler.js
- D:\Web\Project\RenHai1_admin-1\renhai_admin\node_modules\html-webpack-plugin\index.js
- D:\Web\Project\RenHai1_admin-1\renhai_admin\node_modules\react-scripts\config\webpack.config.js
- D:\Web\Project\RenHai1_admin-1\renhai_admin\node_modules\react-app-rewired\scripts\start.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:885:15)
    at Function.Module._load (internal/modules/cjs/loader.js:730:27)
    at Module.require (internal/modules/cjs/loader.js:957:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (D:\Web\Project\RenHai1_admin-1\renhai_admin\node_modules\html-webpack-plugin\lib\child-compiler.js:14:28)
    at Module._compile (internal/modules/cjs/loader.js:1068:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Module.load (internal/modules/cjs/loader.js:933:32)
    at Function.Module._load (internal/modules/cjs/loader.js:774:14)
    at Module.require (internal/modules/cjs/loader.js:957:19) { 
   
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'D:\\Web\\Project\\RenHai1_admin-1\\renhai_admin\\node_modules\\html-webpack-plugin\\lib\\child-compiler.js',
    'D:\\Web\\Project\\RenHai1_admin-1\\renhai_admin\\node_modules\\html-webpack-plugin\\lib\\cached-child-compiler.js',
    'D:\\Web\\Project\\RenHai1_admin-1\\renhai_admin\\node_modules\\html-webpack-plugin\\index.js',
    'D:\\Web\\Project\\RenHai1_admin-1\\renhai_admin\\node_modules\\react-scripts\\config\\webpack.config.js',
    'D:\\Web\\Project\\RenHai1_admin-1\\renhai_admin\\node_modules\\react-app-rewired\\scripts\\start.js'
  ]
}

查了之后发现是因为没有安裝webpack-cli
安装之后根本和主要问题没关系 webpack版本仍然存在问题
其中还去手动更改了node_modules/webpack/package.json里面配置项——不行

根据上面提示的第二种方法

If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.

解决了 但是出现了 接下来的问题


./node_modules/antd/es/button/style/index.less (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-8-1!./node_modules/postcss-loader/src??postcss!./node_modules/resolve-url-loader??ref--5-oneOf-8-3!./node_modules/less-loader/dist/cjs.js??ref--5-oneOf-8-4!./node_modules/antd/es/button/style/index.less)
TypeError: this.getOptions is not a function

我不理解

总之 最后解决的方法是—重点

  1. npm install webpack@4.44.2
  2. "less": "^3.9.0", "less-loader": "^4.1.0",
  3. npm i

我不理解为什么我运行npm install webpack@4.44.2的时候package.json中不显示"webpack": "^4.44.2"难道我当时思绪混乱了一直想着全局问题,而这个是局部安裝去解决我没有这样执行过,一直在npm i后面加-g
——可能是吧

接着第二步也可以在终端指定版本号下载,他就是来解决下面这个问题的


./node_modules/antd/es/button/style/index.less (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-8-1!./node_modules/postcss-loader/src??postcss!./node_modules/resolve-url-loader??ref--5-oneOf-8-3!./node_modules/less-loader/dist/cjs.js??ref--5-oneOf-8-4!./node_modules/antd/es/button/style/index.less)
TypeError: this.getOptions is not a function

原来这个问题也是版本号的问题,直接下载npm i less less-loader下载的都是最新版,导致less-loader版本过高10.xx.xx,导致版本不匹配,搜索之后发现应该是"less": "^3.9.0", "less-loader": "^4.1.0"这样。
总之,忙活了一上午,可算给解决了,以后出现问题最重要的是思路清晰,一步步去尝试,一步步去解决…

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/169229.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 探索SQL Server元数据(三):索引元数据

    探索SQL Server元数据(三):索引元数据

    2021年11月27日
    65
  • 在Ubuntu中安装交叉编译器_为什么一直安装中

    在Ubuntu中安装交叉编译器_为什么一直安装中本文讲述了在Ubuntu中安装pycharm的具体步骤准备环境:Ubuntu21.10,Pycharm2021.1.3具体步骤:1.首先下载pycharm:Pycharm官方下载地址我在这里选择的是2021.1.3的专业版,选择下载Linux版本的pycharm下载好的pycharm如图所示:2.右键点击刚刚下载的文件,选择提取到此处3.打开终端,输入cd命令行,进入刚刚解压文件夹下的bin文件夹,命令行是cd文件夹名称,并按回车键cdpycharm-professional-20

    2025年7月23日
    4
  • 计算机进制及转换_计算机运算 进制转换

    计算机进制及转换_计算机运算 进制转换计算机使用二进制,另外常用的还有八进制、十进制和十六进制。进制特点及表示方法(1)二进制:满2进1,0~1表示,在JDK1.7之前程序中不容许定义二进制数字,从JDK1.7开始可以定义。一般以0b

    2022年8月3日
    11
  • 工控机上位机软件的开发历程(二)[通俗易懂]

    工控机上位机软件的开发历程(二)[通俗易懂]仪器归一化设计这是具体内容的第一篇,我们先来讲述仪器的归一化设计。仪器是各种功能都有的,我只举我们在环境监测这方面所用到的仪器。我们要测试水是不是有污染物质,污染到什么程度,我们要测试水体的高锰酸盐指数、氨氮、总磷、总氮等值。我们的站房有一个后备电源,我们要知道市电是否断电了,是否在用备用电源。我们的站房是有空调的,我希望知道站房的温度和湿度,于是就有了一个温湿度计。我们可能还会有流量计、…

    2022年5月18日
    54
  • 360 c语言 笔试,奇虎360校招的笔试真题「建议收藏」

    360 c语言 笔试,奇虎360校招的笔试真题「建议收藏」选择题有45个?好像是,三道简答题,简答题:1、设计一个课程表(包括目标人群、核心功能、特色设计);2、说ATM的缺点,改进方法;3、如何让李开复等互联网大牌关注你的微薄?选择题记得不是很清楚,大概是这样的:1、数字推理:1,4,5,6,7,9,11,()2、安卓系统是什么语言开发的?c,c++,java,**3、HTML5不包含的技术?选项有JS、java、*、*4、12个鸡蛋,有一个重量与其他…

    2022年7月14日
    35
  • 泰克|安捷伦|普源|PICO示波器程控软件二次开发NS-Scope

    泰克|安捷伦|普源|PICO示波器程控软件二次开发NS-Scope*主要功能:硬件连接;参数配置;运行参数;数据查询。*程控对象:示波器。*程控接口:兼容市面上所有具有GPIB、USB、RS232、LAN、RS485、TTL任意一种程控接口的示波器。*仪器兼容性:泰克Tektronix、是德科技Keysight、普源Rigol、力科、罗德与施瓦茨R&S等品牌示波器。1.软件概述>>为了解决示波器测试操作流程繁琐、参数配置复杂等问题,Namisoft开发的NS-Scope示波器自动化测试程控软件,通过对示波器的程序控制,…

    2022年10月12日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号