找不到模块 'babel-core',但已安装了 @babel/core。

13
在运行 jest 测试之后,其中一个测试出现了这个错误。
Cannot find module 'babel-core'

      at Object.<anonymous> (node_modules/vue-jest/lib/compilers/babel-compiler.js:1:15)

很简单。未安装babel-core。但是安装了更新版本的babel-core(@babel/core)!

这里我添加了package.json devDependencies

"devDependencies": {
    "@babel/core": "^7.4.5",
    "@babel/preset-env": "^7.4.5",
    "@babel/runtime": "^7.4.4",
    "@vue/cli-plugin-babel": "^3.7.0",
    "@vue/cli-plugin-eslint": "^3.7.0",
    "@vue/cli-plugin-pwa": "^3.7.0",
    "@vue/cli-service": "^3.7.0",
    "@vue/test-utils": "^1.0.0-beta.29",
    "axios-mock-adapter": "^1.16.0",
    "babel-eslint": "^10.0.1",
    "babel-loader": "^8.0.6",
    "babel-preset-env": "^1.7.0",
    "bootstrap": "^4.3.1",
    "eslint": "^5.8.0",
    "eslint-plugin-vue": "^5.0.0",
    "gulp-babel": "^8.0.0",
    "jest": "^24.8.0",
    "jest-serializer-vue": "^2.0.2",
    "jest-transform-stub": "^2.0.0",
    "jest-watch-typeahead": "^0.3.1",
    "json-loader": "^0.5.7",
    "less-loader": "^4.1.0",
    "postcss-flexbugs-fixes": "^4.1.0",
    "postcss-loader": "^3.0.0",
    "raw-loader": "^2.0.0",
    "sw-precache-webpack-plugin": "^0.11.5",
    "vue-jest": "^3.0.4",
    "vue-loader": "^15.7.0",
    "vue-template-compiler": "^2.5.21",
    "webpack": "^4.32.0",
    "webpack-cli": "^3.3.2"
  },

我想知道如何让我的babel loader或jest识别@babel/core而不是babel-core。我读到babel-loader 8+应该可以解决这个问题,但它并没有像预期的那样工作。

之前不知道这是一个vue-jest的问题,谢谢。


1
@babel/core 和 babel-core 是不同的。 - Nikko Khresna
1
我知道,babel core 有不同的版本。这就是我不明白的原因。为什么它要求 babel-core 而不是 @babel/core? - Jalil
可能是Vue-jest找不到babel的重复问题。 - SuperDJ
1
Babel 7与Babel 6不向下兼容。如果您想使用它,您需要升级所有相关依赖项到Babel 7(@babel/core)。 - connexo
1个回答

11

我在使用babel-core时遇到了很多错误,我想尝试使用vue-jest 4。 - Jalil

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接