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-node/jest doesn't pass options from tsconfig to swc properly #700

Closed
meskill opened this issue Feb 24, 2023 · 2 comments · Fixed by #702
Closed

@swc-node/jest doesn't pass options from tsconfig to swc properly #700

meskill opened this issue Feb 24, 2023 · 2 comments · Fixed by #702

Comments

@meskill
Copy link
Contributor

meskill commented Feb 24, 2023

After upgrading from 1.5.5 to 1.6.2 I get next error related to legacyDecorators:

 FAIL  packages/createApp.test.ts
  ● Test suite failed to run


      × Expression expected
        ╭─[/workspaces/app/createApp.test.ts:11:1]
     11 │   it('Создание и запуск приложения', async () => {
     13 │ 
     14 │     @Module({
        ·     ─
     15 │       providers: [
     16 │         {
     17 │           provide: 'level-3',
        ╰────


    Caused by:
        Syntax Error

      at Compiler.transformSync (node_modules/@swc/core/index.js:241:29)
      at transformSync (node_modules/@swc/core/index.js:348:21)
      at transformJest (node_modules/@swc-node/core/index.ts:74:2)
      at Object.process (node_modules/@swc-node/jest/index.ts:33:27)
      at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:519:31)
      at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:648:40)
      at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:700:19)

The source problem of the issue:

  1. This code converts @swc-node/jest options to swc options
  2. This code provides options from the tsconfig file to @swc-node/jest options
  3. As now the second piece of code defines swc property it overrides the whole jsc setup in the first piece of code.

The log of the input options and result options are following:

// before transform
 {
  module: 'commonjs',
  sourcemap: 'inline',
  experimentalDecorators: true,
  emitDecoratorMetadata: false,
  esModuleInterop: true,
  swc: {
    filename: '/workspaces/app/createApp.test.ts',
    inputSourceMap: undefined,
    sourceRoot: undefined,
    jsc: {
      externalHelpers: true,
      parser: [Object],
      paths: {},
      keepClassNames: true,
      target: 'es2015',
      transform: [Object]
    }
  }
}
// after transform
 {
  filename: '/workspaces/app/createApp.test.ts',
  jsc: {
    externalHelpers: true,
    parser: { syntax: 'typescript', tsx: true, dynamicImport: true },
    paths: {},
    keepClassNames: true,
    target: 'es2015',
    transform: { react: [Object] }
  },
  minify: false,
  isModule: true,
  module: { type: 'commonjs', noInterop: false },
  sourceMaps: 'inline',
  inlineSourcesContent: true,
  swcrc: false,
  inputSourceMap: undefined,
  sourceRoot: undefined
}

Possible solution

Either use deepMerge to merge all of the options or use another way to provide defaults from tsconfig file

@felixmosh
Copy link

Having the same thing with @swc-node/loader

@otaviosoares
Copy link
Contributor

I have a similar issue with @swc-node/register. After debugging, I believe it was introduced on 1d557ec af643b8. From 1.5.6 and onwards it's setting a default swc config during compilation.

In my case, running with SWCRC=true ...... solves the problem because it forces it to use the config in .swcrc.

However, I believe it's a bug.

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

Successfully merging a pull request may close this issue.

3 participants