swc: @swc/core behavior inconsistency between macOS and Linux

Describe the bug

When requiring two different versions of @swc/core (for example, two dependencies requires two different versions of @swc/core) in Linux, an error is thrown, but not in macOS.

The error message in Linux is:

Error: /dir_to_home/swc-inconsistency/node_modules/.pnpm/@swc+core-linux-x64-gnu@1.2.147/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node: cannot allocate memory in static TLS block
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1122:18)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/dir_to_home/swc-inconsistency/node_modules/.pnpm/@swc+core@1.2.147/node_modules/@swc/core/binding.js:181:45)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)

I test it in macOS 12.3 with Node.js 14.18.1 and Debian 9 with Node.js 14.16.1.

I create a reproduce repo in https://github.com/roland-reed/swc-inconsistency.

Input code

No response

Config

No response

Playground link

No response

Expected behavior

It should not throw error in Linux when requiring two different versions of @swc/core.

Actual behavior

No response

Version

@swc/core@1.2.156

Additional context

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 5
  • Comments: 16 (7 by maintainers)

Most upvoted comments

Do not run @swc/core in worker_thread is a valid workaround. I’ll fix this problem soon.

@kdy1 please reopen this issue and assign it to me. I observed this issue in other packages after upgrading zig from 0.9.0 to 0.9.1.

@Brooooooklyn and @kdy1, are there any workarounds for this problem?

UPDATE

Actually, we just found the workaround. As described by the OP, it only happens when you have multiple instances running, which was our case. We were using it on a monorepo with 10+ packages.

By moving the dependency upwards to the root package.json, the problem was solved.

Same here with the latest version available on npm today (1.2.174). In my case, it was running on a node:15 image. I just updated the node image to node:16, and it still failed.

No problems running on a M1 mac.

Curiously, I ran it on two containers with different packages of the same monorepo. Error was observed only in one.

node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node: cannot allocate memory in static TLS block
469      at Object.<anonymous> (node_modules/@swc/core/binding.js:181:45)