Npm 持续的笑话错误:需要巴别塔^7.0.0-0“;,但却充满了",;6.26.3“;

Npm 持续的笑话错误:需要巴别塔^7.0.0-0“;,但却充满了",;6.26.3“;,npm,jestjs,babeljs,Npm,Jestjs,Babeljs,每当我使用npm在服务器端安装依赖项时,就会出现一个持久的Jest错误。使用Thread安装相同的依赖项是可行的,但我目前正在一个团队中工作,我们都在使用npm。我已经尝试了所有关于堆栈溢出的建议解决方案,无论是否经过投票,都没有一个对我有效。到目前为止,我问过的两位高级开发人员不认为我在全球安装的npm包中有任何东西会导致这种情况 我运行的每个Jest测试套件都会出现以下错误: ● 测试套件无法运行 Requires Babel "^7.0.0-0", but was loaded with

每当我使用npm在服务器端安装依赖项时,就会出现一个持久的Jest错误。使用Thread安装相同的依赖项是可行的,但我目前正在一个团队中工作,我们都在使用npm。我已经尝试了所有关于堆栈溢出的建议解决方案,无论是否经过投票,都没有一个对我有效。到目前为止,我问过的两位高级开发人员不认为我在全球安装的npm包中有任何东西会导致这种情况

我运行的每个Jest测试套件都会出现以下错误:

● 测试套件无法运行

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 tolook for the first entry that doesn't mention "@babel/core" or "babel-core" to see what is calling Babel.

  at throwVersionError (node_modules/@babel/helper-plugin-utils/lib/index.js:65:11)
  at Object.assertVersion (node_modules/@babel/helper-plugin-utils/lib/index.js:13:11)
  at _default (node_modules/@babel/plugin-proposal-decorators/lib/index.js:35:7)
  at node_modules/@babel/helper-plugin-utils/lib/index.js:19:12
  at Function.memoisePluginContainer (../../../node_modules/babel-core/lib/transformation/file/options/option-manager.js:113:13)      at Function.normalisePlugin (../../../node_modules/babel-core/lib/transformation/file/options/option-manager.js:146:32)      at ../../../node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
      at Array.map (<anonymous>)
  at Function.normalisePlugins (../../../node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
  at OptionManager.mergeOptions (../../../node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
  at OptionManager.init (../../../node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
  at File.initOptions (../../../node_modules/babel-core/lib/transformation/file/index.js:212:65)
  at new File (../../../node_modules/babel-core/lib/transformation/file/index.js:135:24)
  at Pipeline.transform (../../../node_modules/babel-core/lib/transformation/pipeline.js:46:16)
} }

这是我的.babelrc文件:

{
  "presets": [
   "@babel/preset-env"
  ],
  "plugins": [
    [
      "@babel/plugin-proposal-decorators",
      {
        "decoratorsBeforeExport": true
      }
    ],
    "@babel/plugin-proposal-class-properties"
  ]
}

问题在于jest依赖关系。我也遇到了同样的问题,通过将下面的步骤添加到package.json文件中解决了这个问题

"scripts": {
  ...
  "postinstall": "rimraf node_modules/jest-runtime/node_modules/babel-core node_modules/jest-config/node_modules/babel-core",
  ...  
}
希望这对您有所帮助。

正如前面所说,出现此错误是因为您在项目中使用了Babel 7,而jest仍然使用Babel 6

我也遇到了同样的问题,我通过安装
babel core@^7.0.0-bridge.0

另见:

谢谢你的建议。这在我的情况下不起作用,但我感谢您的帮助。没问题,只要确保您有
rimraf
可用,并且命令运行成功,因为我的环境中也存在此问题:)我将检查它并报告它是否起作用。谢谢!!:)
"scripts": {
  ...
  "postinstall": "rimraf node_modules/jest-runtime/node_modules/babel-core node_modules/jest-config/node_modules/babel-core",
  ...  
}