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 cant use env with jsc.target #7759

Closed
jleider opened this issue Aug 4, 2023 · 4 comments
Closed

swc/jest cant use env with jsc.target #7759

jleider opened this issue Aug 4, 2023 · 4 comments
Assignees
Labels
Milestone

Comments

@jleider
Copy link

jleider commented Aug 4, 2023

Describe the bug

I think due to changes here: #6956 that state you can't set both env and jsc.target causes issues with swc/jest. I have an env specified in my .swcrc for bundling code for the web. However, when running jest it complains that env and jsc.target can not be used together. I have tried passing an empty object for env and setting env to null on the custom swc config passed to swc/jest as well as manually reading the .swcrc file and deleting the env property, however I still get an error saying they can not be used together.

Input code

const fs = require("fs");

const swcConfig = JSON.parse(fs.readFileSync(".swcrc", "utf-8"));
delete swcConfig.env;


module.exports = {
  cacheDirectory: "./node_modules/.cache/jest",
  clearMocks: true,
  setupFilesAfterEnv: [
    "jest-extended/all",
    "./jest.setup.js",
  ],
  testEnvironment: "jest-environment-jsdom",
  testRegex: ".*\\.(test|spec)\\.(j|t)sx?$",
  transform: {
    "^.+\\.tsx?$": ["ts-jest", {
      tsconfig: "./tests/tsconfig.json",
      babelConfig: "./babel.config.json",
    }],
    "^.+\\.js$": ["@swc/jest", swcConfig],
    "^.+\\.svg$": "<rootDir>/tests/react/svgJest",
    "^.+node_modules/(d3-array|internmap|htmldiff|escape-string-regexp|preact).+\\.jsx?$": "jest-esm-transformer",
  },
  verbose: true,
};

Config

{
  "$schema": "http://json.schemastore.org/swcrc",
  "env": {
    "mode": "usage",
    "coreJs": "3.32.0"
  },
  "jsc": {
    "externalHelpers": true,
    "loose": true,
    "parser": {
      "decorators": true,
      "dynamicImport": true,
      "syntax": "typescript",
      "tsx": true
    },
    "transform": {
      "react": {
        "runtime": "automatic"
      }
    }
  },
  "module": {
    "type": "es6",
    "ignoreDynamic": true
  },
  "sourceMaps": true
}

Playground link

No response

Expected behavior

I would expect to be able to overwrite the env data by passing a custom swc config object to swc/jest.

Also, the error message itself is fairly cryptic because swc/jest seems to automatically apply a jsc.target implicitly. Its non-obvious as to why this even fails at first.

Actual behavior

Receive an error from jest:

`env` and `jsc.target` cannot be used together

Version

1.3.72

Additional context

No response

@jleider jleider added the C-bug label Aug 4, 2023
@kdy1 kdy1 added this to the Planned milestone Aug 6, 2023
@kdy1 kdy1 self-assigned this Aug 6, 2023
@kdy1 kdy1 modified the milestones: Planned, v1.3.75 Aug 8, 2023
@inomdzhon
Copy link

inomdzhon commented Aug 8, 2023

Hi, @kdy1

I have the same problem when build package with @swc/core v1.3.75

Please, see PR by Dependabot VKCOM/icons#672

Config here https://github.com/VKCOM/icons/blob/ea0be2d360b3f0a7ea9e9750537875c72c5eb8c0/packages/icons-scripts/scripts/configs/.swcrc#L1-L13

@kdy1
Copy link
Member

kdy1 commented Aug 8, 2023

@inomdzhon Look at your .swcrc

@inomdzhon
Copy link

@inomdzhon Look at your .swcrc

Ohhh I got it #7704

Thanks 🙏

@swc-bot
Copy link
Collaborator

swc-bot commented Sep 8, 2023

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Sep 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

4 participants