【问题标题】:How to fix: this.setDynamic is not a function如何修复:this.setDynamic 不是函数
【发布时间】:2019-10-23 10:58:56
【问题描述】:

我的 babel 配置有问题,不知道是什么问题..

我看到的错误:

 ERROR  Failed to compile with 1 errors                                                                                          friendly-errors 21:27:50


 ERROR  in ./.nuxt/client.js                                                                                                     friendly-errors 21:27:50

Module build failed (from ./node_modules/@nuxt/webpack/node_modules/babel-loader/lib/index.js):                                  friendly-errors 21:27:50
TypeError: this.setDynamic is not a function

我的 .babelrc 看起来像这样:

{
  "presets": [
    [
      "vue-app",
      {
        "useBuiltIns": true
      }
    ],
    "flow"
  ],
  "plugins": ["@babel/plugin-proposal-decorators", "@babel/plugin-proposal-class-properties"],
  "env": {
    "test": {
      "plugins": ["babel-jest-assertions", "transform-runtime"]
    }
  }
}

包锁,安装插件:

"@babel/core": "^7.4.5",
    "@babel/preset-env": "^7.4.5",
    "@nuxtjs/google-analytics": "^2.2.0",
    "acorn": "^6.1.1",
    "axios": "^0.18.1",
    "babel-jest-assertions": "^0.1.0",
    "babel-plugin-transform-decorators-legacy": "^1.3.5",
    "babel-preset-flow": "^6.23.0",

需要更改哪些配置才能正常工作?访问过各种 stackoverflow 答案,但尚未找到有效的修复方法。

评论后更新配置:

"@babel/plugin-transform-runtime": "^7.4.4",
    "@babel/polyfill": "^7.4.4",
    "@vue/babel-preset-app": "^3.0.0-rc.2",
    "autoprefixer": "^7.1.2",
    "babel-core": "^6.26.3",
    "babel-eslint": "^8.2.3",
    "babel-helper-vue-jsx-merge-props": "^2.0.3",
    "babel-jest": "^21.0.2",
    "babel-loader": "^8.0.0-beta.0",
    "babel-plugin-dynamic-import-node": "^1.2.0",
    "babel-plugin-syntax-jsx": "^6.18.0",
    "babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
    "babel-plugin-transform-imports": "^1.5.1",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-plugin-transform-vue-jsx": "^3.5.0",
    "babel-preset-env": "^1.3.2",
    "babel-preset-stage-2": "^6.22.0",
    "babel-register": "^6.22.0",

【问题讨论】:

  • 你安装了babel-plugin-transform-runtime吗?
  • 安装它并将其添加到您的插件"plugins": ["@babel/plugin-transform-runtime"...]
  • @OrthoHomeDefense 是的,我愿意。确认并重新运行后仍然看到相同的错误
  • 它是什么版本?您也将其添加到插件部分吗?
  • 你应该将“transform-runtime”升级到“@babel/plugin-transform-runtime”,确保它是更高版本的 v7 或更高版本卸载 babel-plugin-transform-runtime 并安装 @babel/plugin-transform -runtime 并确保安装 @babel/runtime

标签: vue.js webpack babeljs nuxt.js babel-loader


【解决方案1】:

这个问题的答案是这样的。请注意您的 babel 配置,即像 cmets 中提到的那样。 Babel 6 无法与 Babel 7 插件等一起正常工作。感谢您在 cmets 中提供的所有帮助。

【讨论】:

    猜你喜欢
    • 2019-03-24
    • 2019-01-13
    • 2021-11-02
    • 2019-10-28
    • 2020-09-12
    • 2019-05-30
    • 2019-06-13
    • 2021-10-07
    • 2019-09-28
    相关资源
    最近更新 更多