【问题标题】:VueJS and Jest : Cannot find module 'babel-core'VueJS 和 Jest:找不到模块“babel-core”
【发布时间】:2020-04-02 19:26:05
【问题描述】:

我正在尝试将 Jest 与 VueJS 一起使用,但是我收到了 Cannot find module 'babel-core' at Object.<anonymous> (node_modules/vue-jest/lib/compilers/babel-compiler.js:1:15)

我可以解决这个问题的唯一方法是添加

"@babel/core": "^7.7.5",
"babel-core": "^7.0.0-beta.47",

然后测试通过,但我不想在我的 package.json 中保留 'beta' 版本,而且将 @babel/corebabel-core 放在一起很奇怪,因为知道它们是不同版本的同一个包。

我看到错误似乎在 Vue-Jest 中,但它已经在最新版本中。

下面是我当前的 package.json 中断(没有 "babel-core": "^7.0.0-beta.47"

"dependencies": {
    "@vue/babel-preset-app": "^3.12.1",
    "axios": "^0.19.0",
    "chai": "^4.2.0",
    "date-fns": "^1.30.1",
    "jwt-decode": "^2.2.0",
    "lodash": "^4.17.15",
    "moment": "^2.24.0",
    "register-service-worker": "^1.5.2",
    "v-click-outside": "^2.1.5",
    "vue": "^2.6.10",
    "vue-alertify": "^1.1.0",
    "vue-body-class": "^2.0.0-beta.2",
    "vue-clipboard2": "^0.3.1",
    "vue-mq": "^0.1.3",
    "vue-multiselect": "^2.1.6",
    "vue-recaptcha-v3": "^1.8.0",
    "vue-router": "^3.1.3",
    "vue-the-mask": "^0.11.1",
    "vuelidate": "^0.7.4",
    "vuex": "^3.1.2",
    "vuex-persist": "^2.2.0"
  },
  "devDependencies": {
    "@babel/core": "^7.7.5",
    "@babel/plugin-transform-modules-commonjs": "^7.7.5",
    "@babel/polyfill": "^7.7.0",
    "@babel/preset-env": "^7.7.5",
    "@vue/cli-plugin-babel": "^3.12.1",
    "@vue/cli-plugin-eslint": "^3.12.1",
    "@vue/cli-plugin-pwa": "^3.12.1",
    "@vue/cli-service": "^3.12.1",
    "@vue/eslint-config-standard": "^4.0.0",
    "@vue/test-utils": "^1.0.0-beta.30",
    "babel-eslint": "^10.0.3",
    "copy-webpack-plugin": "^5.0.5",
    "eslint": "^5.16.0",
    "eslint-plugin-vue": "^5.2.3",
    "eslint-plugin-vue-libs": "^3.0.2",
    "jest": "^24.9.0",
    "vue-jest": "^3.0.5",
    "vue-svg-loader": "^0.12.0",
    "vue-template-compiler": "^2.6.10"
  }

任何帮助将不胜感激。

【问题讨论】:

    标签: vue.js vuejs2 jestjs babeljs


    【解决方案1】:

    只需使用 babel-bridge 。来自github issue

    npm install babel-core@^7.0.0-bridge.0 --save-dev
    

    【讨论】:

      猜你喜欢
      • 2019-02-03
      • 2019-02-17
      • 2019-10-10
      • 2021-09-10
      • 2020-04-18
      • 2017-10-13
      • 2020-04-15
      • 1970-01-01
      • 2019-09-04
      相关资源
      最近更新 更多