首页 > 解决方案 > 无法解决此问题:错误:需要 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';

我尝试了什么:

每次我尝试,它都会给我同样的错误

我检查了什么:

Who required @babel/helpers:
opews > @babel/core > @babel/helpers@7.10.4

标签: javascriptnode.jsnpmbabeljs

解决方案


推荐阅读