Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@swc/jest incompatible with arrays in .swcrc #115

Open
abrenneke opened this issue Jul 28, 2022 · 4 comments
Open

@swc/jest incompatible with arrays in .swcrc #115

abrenneke opened this issue Jul 28, 2022 · 4 comments

Comments

@abrenneke
Copy link

abrenneke commented Jul 28, 2022

Similar issue in swc-loader

I'm not exactly sure where the linked documentation in that other issue went, I could have sworn it was on the swc website - but swc supports the .swcrc being an array of configurations to allow one configuration to parse both TS and JS.

@swc/jest assumes that the swcrc is an object, so tries to spread values into it, causing the configuration to get all mangled since an array is spread into an object.

Failed to deserialize buffer as swc::config::Options
    JSON: {"0":{"test":".*.tsx?$","exclude": etc

Version: 0.2.22

.swcrc:

[
  {
    "test": ".*.tsx?$",
    "exclude": ["node_modules", "/lib-types/", "typings", ".*\\.d\\.ts"],
    "jsc": {
      "parser": {
        "syntax": "typescript",
        "tsx": true,
        "decorators": true,
        "dynamicImport": true
      },
      "transform": {
        "legacyDecorator": true
      },
      "target": "es2016",
      "externalHelpers": true
    },
    "module": {
      "type": "commonjs",
      "ignoreDynamic": true
    },
    "sourceMaps": true
  },
  {
    "test": ".*.jsx?$",
    "exclude": ["node_modules", "/lib-types/", "typings"],
    "jsc": {
      "parser": {
        "syntax": "ecmascript",
        "jsx": true,
        "decorators": true,
        "dynamicImport": true,
        "decoratorsBeforeExport": true
      },
      "transform": {
        "legacyDecorator": true
      },
      "target": "es2016",
      "externalHelpers": true
    },
    "module": {
      "type": "commonjs",
      "ignoreDynamic": true
    },
    "sourceMaps": true
  }
]
@moderndegree

This comment was marked as spam.

@zhutuzhao

This comment was marked as spam.

@craigmiller160
Copy link

This issue is definitely real. However, here is a workaround that can allow @swc/jest to work until this is more permanently resolved. This workaround mirrors what is described in the swc-loader issue that OP linked to.

// jest.config.js

const fs = require('fs')

const config = JSON.parse(fs.readFileSync(`${__dirname}/.swcrc`, 'utf-8'))

module.exports = {
    transform: {
        '^.+\\.jsx?$': ['@swc/jest', config[1]],
        '^.+\\.tsx?$': ['@swc/jest', config[0]],
    },
};

@opjarretop
Copy link

opjarretop commented Jan 30, 2024

I hadnt had this issue until upgrading to 0.2.31. upgraded from 0.2.29 which allowed me to use. Curious what changed.

  transform: {
    "^.+\\.(t|j)sx?$": "@swc/jest",
  },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants