Babel 7 update mucking up jest tests with Cannot use the decorators and decorators-legacy plugin together

Viewed 1939

I am upgrading to Babel 7 and though the app is loading, my tests are mucking up. They were fine before. I am getting this error from every test that involves a decorated component.

 FAIL  src/app/components/pages/Home/__tests__/Home.test.js
  ● Test suite failed to run

    Cannot use the decorators and decorators-legacy plugin together

      at validatePlugins (node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:10401:13)
      at getParser (node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:10464:5)
      at parse (node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:10448:12)
      at parser (node_modules/@babel/core/lib/transformation/normalize-file.js:170:34)
      at normalizeFile (node_modules/@babel/core/lib/transformation/normalize-file.js:138:11)
      at runSync (node_modules/@babel/core/lib/transformation/index.js:44:43)
      at transformSync (node_modules/@babel/core/lib/transform.js:43:38)
      at transform (node_modules/@babel/core/lib/transform.js:22:38)

.babelrc please note: I am using remove-decorators to run my tests as couldn't get jest to work w/o it. You think this might be the issue?

  "plugins": [
    "@babel/plugin-proposal-class-properties",
    "@babel/plugin-proposal-object-rest-spread",
    ["@babel/plugin-proposal-decorators", { legacy: true } ],
    "babel-plugin-styled-components"
  ],
  "env": {
    "development": {
      "plugins": [
        "@babel/plugin-proposal-class-properties",
        "@babel/plugin-proposal-object-rest-spread",
        ["@babel/plugin-proposal-decorators", { legacy: true } ],
        "babel-plugin-styled-components"
      ]
    },
    "test": {
      "plugins": [
        "remove-decorator"
      ]
    }

package.json

  "devDependencies": {
    "@babel/core": "^7.0.0",
    "@babel/plugin-proposal-class-properties": "^7.0.0",
    "@babel/plugin-proposal-decorators": "7.0.0",
    "@babel/plugin-proposal-object-rest-spread": "^7.0.0",
    "@babel/polyfill": "^7.0.0",
    "@babel/preset-env": "^7.0.0",
    "@babel/preset-flow": "^7.0.0",
    "@babel/preset-react": "^7.0.0",
    "babel-core": "^7.0.0-bridge.0",
    "babel-jest": "^21.2.0",
    "babel-loader": "^8.0.0",
    "babel-plugin-remove-decorator": "^1.0.0",
    "babel-plugin-styled-components": "^1.3.0",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-polyfill": "6.26.0",
1 Answers

I solved this problem npm install -D @babel/plugin-proposal-decorators and

"test": {
  "plugins": [["@babel/plugin-proposal-decorators", { "decoratorsBeforeExport": true }], "remove-decorator"]
}

adding this to my babel.conf.js file.

Related