jscutlery/devkit

swc-angular-preset in nx monorepo: RuntimeError: out of bounds memory access

alexciesielski opened this issue · 1 comments

Prerequisites

  • clean nx monorepo with a single Angular app (although same error observed in a big monorepo with multiple apps and libs)
  • preset applied to the application-specific jest.config.ts here
  • application-specific test-setup.ts here

Reproduction

  1. Setup clean nx monorepo
  2. Follow instructions for setting up swc-angular-preset
  3. nx test nx-test

or just clone the above repository and run npm install --force and nx test nx-test

Test suite failed to run

    failed to handle: failed to invoke plugin: failed to invoke plugin on 'Some("/Users/alexciesielski/Documents/nx-test/apps/nx-test/src/test-setup.ts")'

    Caused by:
        0: failed to invoke `@jscutlery/swc-plugin-angular` as js transform plugin at @jscutlery/swc-plugin-angular
        1: RuntimeError: out of bounds memory access

      at Compiler.transformSync (../../node_modules/@swc/core/index.js:244:29)
      at transformSync (../../node_modules/@swc/core/index.js:351:21)
      at Object.process (../../node_modules/@swc/jest/index.js:73:45)
      at ScriptTransformer.transformSource (../../node_modules/@jest/transform/build/ScriptTransformer.js:545:31)
      at ScriptTransformer._transformAndBuildScript (../../node_modules/@jest/transform/build/ScriptTransformer.js:674:40)
      at ScriptTransformer.transform (../../node_modules/@jest/transform/build/ScriptTransformer.js:726:19)
image

Thank you @alexciesielski for raising the issue and bringing a repro 😊

TL;DR: Updating to @swc/core@1.4.13 should fix it

This happens because it is not using the right version of @swc/core. The --force flag forced the install of the incompatible version of @swc/core.

More precisely, @swc/core@1.4.0 introduced breaking changes so we are not backwards compatible with 1.3.x
Cf. https://swc.rs/docs/plugin/selecting-swc-core

We'll keep this issue open until we detect the @swc/core version dynamically and provide a nicer error message.