【问题标题】:Unknown plugin in babelrc when running jest运行 jest 时 babelrc 中的未知插件
【发布时间】:2019-07-27 08:13:29
【问题描述】:

我有一个项目,它使用 Parcel 来构建和 Babel 来编译。

当我尝试开玩笑时,我得到了

Test suite failed to run
ReferenceError: Unknown plugin "syntax-dynamic-import" specified in "/app/.babelrc" at 0, attempted to resolve relative to "/app"

通过Parcel正常运行发现插件成功,并在我的package.json的依赖项中列出&安装。

我的 babelrc:

{
  "presets": [
    "@babel/preset-env",
    "@babel/preset-react"
  ],
  "plugins": [
    "@babel/syntax-dynamic-import",
  ],
    "env": {
    "test": {
      "plugins": ["dynamic-import-node"]
    }
  }
}

在 package.json 中:

  "dependencies": {
    "@material-ui/core": "^3.6.0",
    "@material-ui/icons": "^3.0.1",
    "express": "^4.16.4",
    "react": "^16.6.3",
    "react-dom": "^16.6.3",
    "jest": "^23.6.0",
    "babel-jest": "^23.6.0",
    "babel-plugin-dynamic-import-node": "^2.2.0"
  },
  "devDependencies": {
    "@babel/core": "^7.1.6",
    "@babel/plugin-syntax-dynamic-import": "^7.0.0",
    "@babel/preset-env": "^7.0.0",
    "@babel/preset-react": "^7.0.0",
    "eslint-plugin-jsx-a11y": "^6.1.2",
    "eslint-plugin-react": "^7.11.1",
    "http-proxy-middleware": "^0.19.0",
    "less": "^2.0.0",
    "parcel-bundler": "^1.10.3",
    "parcel-plugin-eslint": "^1.0.4"
  },

完整的项目代码可以在on Glitch找到。重新混合项目以获得您自己的版本,您可以编辑并尝试在其上运行脚本。

【问题讨论】:

    标签: jestjs babel-jest parceljs


    【解决方案1】:

    我收到了the following response when I posted this as a bug in the Jest GitHub repo

    在.babelrc中,我的插件应该这样定义:

    @babel/plugin-syntax-dynamic-import
    

    由于我使用的是 Jest 23,我需要安装 babel-core@bridge 才能使用 babel@7 或者我可以升级到 Jest 24。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-09
      • 2018-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-03
      • 1970-01-01
      • 2017-07-20
      相关资源
      最近更新 更多