在babel升级到7以后,按照其官网的要求,安装了babel 7.0相关的包,具体包括@babel/core, @babel/cli, @babel/@babel/preset-env,@babel/plugin-transform-runtime,@babel/plugin-proposal-class-properties, @babel/plugin-transform-classes,具体安装命令如下:

cnpm install -D '@babel/core' '@babel/cli' '@babel/preset-env' '@babel/plugin-transform-runtime' '@babel/plugin-proposal-class-properties' '@babel/plugin-transform-classes' browserify
cnpm install -S  @babel/runtime

升级.babelrc配置文件为:

"presets": ["@babel/preset-env"], "plugins": [ "@babel/plugin-transform-runtime", "@babel/plugin-proposal-class-properties", "@babel/plugin-transform-classes"

安装后,执行命令将es6代码转换为es5

babel src/ -d build/

命令执行失败,显示错误如下

Error: Requires Babel “^7.0.0-0”, but was loaded with “6.26.3”.If you are sure you have a compatible version of @babel/core, it is likely that something in your build process is loading the wrong version. Inspect the stack trace of this error to look for the first entry that doesn’t mention “@babel/core” or “babel-core” to see what is calling Babel. (While processing preset: “/Users/arthurfontaine/Documents/Lab/opews/parser/node_modules/@babel/preset-env/lib/index.js”)

按照网上提示,又安装了其他相关的包,具体命令如下:

cnpm install -D babel-core@^7.0.0-bridge.0 @babel/core regenerator-runtime 

依旧显示上述错误。继续搜索解决方案,安装新的包,具体如下:

 cnpm install -D jest babel-jest babel-core@^7.0.0-bridge.0 @babel/core

还是没有任何效果。依旧显示上述错误。

问题分析及解决

显然,Babel 7相关的包已经安装,但是6.26.3的包为什么还再起作用?笔者做了一个实验,不再使用全局的babel命令,修改为使用当前项目安装的babel命令,具体如下:

.\node_modules\.bin\babel src -d build

命令执行成功。

之前有同事在全局安装了一个低版本的babel命令,我们虽然更新了当前项目的babel命令,但是没有更新全局的babel命令,所以命令依旧无法执行。

对于webpack报错的情况,我认为道理是一样的。但是由于webpack是默认使用全局babel命令的,所以我们需要升级全局全局的babel命令:

cnpm install -g @babel/core, @babel/cli

全局安装后,babel src -d build命令执行成功。

彻底解决Error: Requires Babel “^7.0.0-0”, but was loaded with “6.26.3”. 的问题问题产生在babel升级到7以后,按照其官网的要求,安装了babel 7.0相关的包,具体包括@babel/core, @babel/cli, @babel/@babel/preset-env,@babel/plugin-transform-runtime,@babel/plugin-proposal-class-properties, @babel/plugin Requires Babel "^7.0.0-0", but was loaded with "6.26.3". If you are sure you have a compatible version of @babel/core, it is likely that something in your build process is loading the wrong version. Inspect the stack trace of this error to loo k for
ERROR in ./src/renderer/main.js Module build failed (from ./node_modules/babel-loader/lib/index.js): Error: Requires Babel “^7.0.0-0”, but was loaded with “6.26.3”. If you are sure you have a compatible version of @babel/core, it is likely that something i
# 第一套包,相当于babel的转换工具 npm i babel-core babel-loader babel-plugin-transform-runtime -D # 第二套包,babel的语法 npm i babel-preset-env babel-preset-stage-0 -D ## 安装第一个包出现报警告 babel-loader@8.0.5 requires a peer o...
    在NodeJs开发中,往往需要安装各种依赖包,而有时候这些依赖包版本更新了或者改成了另外一个包名,导致npm install会报“require a peer of XXX”之类的warning。解决方法,就是缺啥就补啥,命令如下: npm install --save-dev "XXX"     比如,warning报“requires a peer of eslint@>=6.2.2 ”,如图(1)所示: 图(1) warning报"eslint@>=0.62.2" 依赖包缺
npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! Found: @babel/core@7.0.0 npm ERR! node_modules/@babel/core npm ERR! dev @babel/core@"7.0.0" from the root project npm ERR! peer @babel/core@"^7.0.0-0" from @ba..
一、配置文件 几乎所有的前端工程师都知道可以用babeles6+的语法转换为es5,转换工具要么使用babel-cli,要么使用webpackbabel-loader,不管使用哪种转换工具,通常都需要一个配置文件来建立转换规则(也可以在webpackbabel-loader的配置项,原理都一样)。 babel执行时默认从当前目录查找配置文件,支持的配置文件格式有:.babelrc,.babelrc.js,babel.config.js和package.json。它们的配置项都是相同,作用也是一样的
Error: Package: 3:nvidia-driver-latest-NVML-470.199.02-1.el7.x86_64 (nvidia-driver-local-rhel7-470.199.02) Requires: /sbin/ldconfig Error: Package: 3:nvidia-driver-latest-NvFBCOpenGL-470.199.02-1.el7.x86_64 (nvidia-driver-local-rhel7-470.199.02)
这个错误通常表示安装 NVIDIA 驱动程序时缺少必需的依赖项。在这种情况下,缺少的依赖项是 `/sbin/ldconfig`。要解决这个问题,您可以尝试以下几个步骤: 1. 确保您的系统已经安装了 `ldconfig`。您可以运行以下命令来检查它是否已安装: which ldconfig 如果命令输出了 `/sbin/ldconfig` 的路径,则说明已经安装。否则,您可以通过运行以下命令来安装它: sudo yum install glibc 2. 如果您已经安装了 `ldconfig`,但仍然收到错误消息,请尝试重新安装 NVIDIA 驱动程序。您可以按照 NVIDIA 官方文档提供的指南进行操作。 3. 如果问题仍然存在,您可以尝试卸载现有的 NVIDIA 驱动程序并重新安装。您可以使用以下命令卸载驱动程序: sudo yum remove nvidia-driver-latest-NVML sudo yum remove nvidia-driver-latest-NvFBCOpenGL 然后,按照 NVIDIA 官方文档提供的指南重新安装驱动程序。 请注意,对于特定的问题,可能需要更详细的系统信息和日志来确定准确的解决方法。建议您在 NVIDIA 官方论坛或相关技术支持渠道上寻求帮助。
List<Student> listStu = new(); //数据部分省略 if(true){ var testList = listStu.GroupBy(p=>new {p.Id,p.Name}).ToList(); testList不用var,而指定一个实际类型,怎么写呢 我想在if外面定义变量:testList ,下面的处理会用到testList ,求解 [/code]
C# LINQ源码分析之Count 懒人Ethan: 完整模拟代码稍后给出