javascript - 无法解决此问题:错误:需要 Babel“^7.0.0-0”,但加载了“6.26.3”
问题描述
我正在用 NodeJS 开发一个 CLI。我使用 Nodemon 进行开发。所以当我做npm run start
(= nodemon --exec babel-node bin/main.js
)时,一切正常。但是,当我安装我的 CLI(使用npm i -g .
)并运行它(使用opews
(我的 CLI 名称))时,我收到此错误:
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")
这是我的一部分package.json
:
"dependencies": {
"chalk": "^4.1.0",
"dom-parser": "^0.1.6",
"franc": "^5.0.0",
"jsdom": "^16.2.2",
"lda": "^0.2.0",
"minimist": "^1.2.5",
"node-fetch": "^2.6.0",
"node-vibrant": "^3.1.5"
},
"devDependencies": {
"@babel/cli": "^7.10.5",
"@babel/core": "^7.10.5",
"@babel/node": "^7.10.5",
"@babel/preset-env": "^7.10.4",
"nodemon": "^2.0.4"
},
"scripts": {
"start": "nodemon --exec babel-node bin/main.js"
}
我的.babelrc
:
{
"presets": [
"@babel/preset-env"
]
}
和我的标题main.js
:
#!/usr/bin/env babel-node
'use strict';
我尝试了什么:
- 全局卸载
@babel/cli
看是不是加载了全局安装的一个而不是项目一个 - 在我的项目中卸载/重新安装“Babel-related”模块
npm i @babel/cli @babel/node @babel/core @babel/preset-env --save-dev
- 像这里
babel-core@7.0.0-bridge.0
所说的那样安装 - 安装
babel-core
,但它安装6.23.3
版本
每次我尝试,它都会给我同样的错误
我检查了什么:
- 如果
6.23.3
出现在我的package-lock.json
但没有出现 - 正如它在这个问题
npx npm-why @babel/helpers
上所说的那样运行。它返回给我:
Who required @babel/helpers:
opews > @babel/core > @babel/helpers@7.10.4
解决方案
推荐阅读
- laravel - 保存复选框开/关值 - Laravel
- java - 如何将字符串 JSON 值带入 HashMap
- scala - 无法解析符号 mllib
- c++ - 使用 std::vector 保存 BMP 像素图
- javascript - 在 React 中更新父级状态时如何更新子级中的道具?
- r - 在 mlr 中调整 h2o 超参数?
- scala - 将字符串格式的科学记数法转换为 Spark 数据框中的数字
- c# - 使用 NEST 将文档自动映射到弹性搜索中不起作用
- c# - 当我在计时器中使用 xlApp.CutCopyMode 时,我的应用程序不会关闭。为什么会这样?
- android - 何时使用 MutableLiveData 和 LiveData