【问题标题】:Cannot find module 'babel-core' but @babel/core is installed找不到模块 'babel-core' 但已安装 @babel/core
【发布时间】:2019-10-10 20:41:23
【问题描述】:

运行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 问题,但谢谢。

【问题讨论】:

  • @babel/core 和 babel-core 不同
  • 我知道,这是不同版本的 babel core。这就是为什么我不明白。为什么它要求 babel-core?而不是@babel/core?
  • Vue-jest can't find babel的可能重复
  • Babel 7 不向下兼容 Babel 6。如果你想使用它,你需要将所有相关的依赖升级到 Babel 7 (@babel/core)。

标签: javascript vue.js jestjs babeljs


【解决方案1】:

babel-core 不是@babel/core——它们是不同的包。

你应该可以离开这里

【讨论】:

  • 我在使用 babel-core 时遇到了很多错误,我想我会尝试使用 vue-jest 4
猜你喜欢
  • 2021-09-10
  • 2019-02-03
  • 2019-02-17
  • 2020-04-18
  • 2017-10-13
  • 2020-04-02
  • 2019-08-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多