Я получаю постоянную ошибку Jest всякий раз, когда использую npm для установки своих зависимостей на стороне сервера. Использование yarn для установки тех же зависимостей работает, но в настоящее время я работаю в команде, где все мы используем npm. Я пробовал все предлагаемые решения на Stack Overflow, получил или нет, и ни одно из них не помогло мне. Два старших разработчика, которых я спрашивал до сих пор, не думают, что в моих глобально установленных пакетах 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)
Вот как выглядит мой package.json:
{
"name": "nanny-now",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest --verbose --runInBand",
"test:watch": "npm run test -- --watch",
"build": "babel src -d lib -s true",
"start": "node lib/index.js",
"start:watch": "nodemon src/index.js --exec babel-node"
},
"jest": {
"testEnvironment": "node"
},
"repository": {
"type": "git",
"url": ""
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/cli": "^7.1.5",
"@babel/core": "^7.2.0",
"@babel/node": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/plugin-proposal-decorators": "^7.1.6",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/preset-env": "^7.1.6",
"babel-eslint": "^10.0.1",
"babel-jest": "^23.6.0",
"chance": "^1.0.18",
"eslint": "^5.9.0",
"eslint-plugin-babel": "^5.3.0",
"jest": "^23.6.0",
"nodemon": "^1.18.7",
"supertest": "^3.3.0"
},
"dependencies": {
"bcryptjs": "^2.4.3",
"dotenv": "^6.2.0",
"express": "^4.16.4",
"jsonwebtoken": "^8.4.0",
"mongoose": "^5.3.14",
"morgan": "^1.9.1",
"regenerator-runtime": "^0.13.1"
} }
Вот мой файл .babelrc:
{
"presets": [
"@babel/preset-env"
],
"plugins": [
[
"@babel/plugin-proposal-decorators",
{
"decoratorsBeforeExport": true
}
],
"@babel/plugin-proposal-class-properties"
]
}

Проблема в шутливых зависимостях. У меня была такая же проблема, и я решил ее, добавив шаг ниже в мой файл package.json.
"scripts": {
...
"postinstall": "rimraf node_modules/jest-runtime/node_modules/babel-core node_modules/jest-config/node_modules/babel-core",
...
}
Надеюсь это поможет..
Нет проблем, просто убедитесь, что у вас есть rimraf и что команда успешно работает, так как у меня тоже была эта проблема в моей среде :)
Я проверю и сообщу, работает ли он. Спасибо!! :)
Как сообщает Джордж Артемиу, эта ошибка возникает из-за того, что вы используете Babel 7 в своем проекте, в то время как jest по-прежнему использует Babel 6.
У меня была такая же проблема, и я решил ее, установив babel-core@^7.0.0-bridge.0.
Смотрите также: https://github.com/babel/babel-bridge
Спасибо за идею. В моем случае это не сработало, но я ценю помощь.