swc-project / swc

Rust-based platform for the Web
https://swc.rs
Apache License 2.0
30.94k stars 1.21k forks source link

@swc/core threw an error when attempting to validate swc compiler options. #5616

Open sebastianrath opened 2 years ago

sebastianrath commented 2 years ago

Describe the bug

Hi there,

I am using @swc/core to speedup the execution of my test suite with avajs/ava.

System info: Ubuntu 20.04.1 (VM via parallels 18 on a Mac Mini Intel) node 16.15.0

During npm run test I receive the following error, and I am not sure how to resolve the issue.

/home/st/actions-runner/_work/snow/snow/node_modules/ts-node/src/transpilers/swc.ts:262
      throw new Error(
            ^
Error: @swc/core threw an error when attempting to validate swc compiler options.
You may be using an old version of swc which does not support the options used by ts-node.
Try upgrading to the latest version of swc.
Error message from swc:
Bindings not found
    at createVariant (/home/st/actions-runner/_work/snow/snow/node_modules/ts-node/src/transpilers/swc.ts:262:13)
    at createSwcOptions (/home/st/actions-runner/_work/snow/snow/node_modules/ts-node/src/transpilers/swc.ts:211:25)
    at create (/home/st/actions-runner/_work/snow/snow/node_modules/ts-node/src/transpilers/swc.ts:56:41)
    at createTranspiler (/home/st/actions-runner/_work/snow/snow/node_modules/ts-node/src/index.ts:784:16)
    at createTranspileOnlyGetOutputFunction (/home/st/actions-runner/_work/snow/snow/node_modules/ts-node/src/index.ts:1341:28)
    at createFromPreloadedConfig (/home/st/actions-runner/_work/snow/snow/node_modules/ts-node/src/index.ts:1404:34)
    at create (/home/st/actions-runner/_work/snow/snow/node_modules/ts-node/src/index.ts:624:10)
    at register (/home/st/actions-runner/_work/snow/snow/node_modules/ts-node/src/index.ts:591:15)
    at Object.registerAndCreateEsmHooks (/home/st/actions-runner/_work/snow/snow/node_modules/ts-node/src/esm.ts:116:34)
    at file:///home/st/actions-runner/_work/snow/snow/node_modules/ts-node/esm.mjs:8:7
  ✖ test/1.sys.test.ts exited with a non-zero exit code: 1

Input code

No response

Config

Snippet of tsconfig.json config:

  "ts-node": {
    "swc": true
  },

Playground link

No response

Expected behavior

Successful execution of npm run test.

Actual behavior

No response

Version

v1.2.241

Additional context

No response

kdy1 commented 1 year ago

@jaybe78 This is not a bug of swc

littleski commented 1 year ago

I think there is a bug in the postinstall.sh script in the swc module. Somewhere, it "trash" the @swc/wasm module instead of adding it. the script however is discarded if @swc/wasm is added in the dependencies. What fixed it for me (in my dockers in CI), is to add the package in the dependencies. But looking at the comments, i think there is multiple issues listed here, so it may not fix for everyone.

I put it again here, in case it helps someone.

pcdevil commented 1 year ago

adding the core modules as optional dependencies for the project fixed the error for me:

npm install --save-optional \
    "@swc/core-darwin-arm64" \
    "@swc/core-darwin-x64" \
    "@swc/core-linux-arm-gnueabihf" \
    "@swc/core-linux-arm64-gnu" \
    "@swc/core-linux-arm64-musl" \
    "@swc/core-linux-x64-gnu" \
    "@swc/core-linux-x64-musl" \
    "@swc/core-win32-arm64-msvc" \
    "@swc/core-win32-ia32-msvc" \
    "@swc/core-win32-x64-msvc"

you can also filter out the list of packages in case you are certain what is the OS / architecture of your development computer and the CI.

hope this helps for others until the issue is resolved!

kanocarra commented 1 year ago

I was having the same issue Fallback bindings does not support filesystem access. when running in GitHub Actions.

@pcdevil 's response solved the issue - thanks!!

bodinsamuel commented 1 year ago

thanks @pcdevil that was the solution for me (when compiling react-email in docker)

svargas-dev commented 1 year ago

I'm having this issue re-appear with @swc/core@1.3.83 (and @swc/core@1.3.84) on Linux (Debian 12) with a mono repo using npm. If I explicitly install @swc/core@1.3.83 (or @swc/core@latest) in my workspace it doesn't work but explicitly installing the previous version i.e., npm -w=backend i -D @swc/core@1.3.82, is a good workaround for now.

EDIT: My issue is actually a ts-node issue. See: https://github.com/TypeStrong/ts-node/issues/2059 https://github.com/TypeStrong/ts-node/issues/2056

corazon-roto commented 9 months ago

I can work around this by simply yarn add -D @swc/core@latest.

MohitOru commented 7 months ago

just clear node_modules files and do npm install

jwalton commented 6 months ago

I worked around this with:

npm install --save-dev @swc/core@1.3.2 @swc/cli@0.1.57
npm install @swc/helpers@0.4.11

These are pretty old versions - there's likely newer ones that work, I just grabbed these from a project where I didn't have this issue.

throrin19 commented 4 months ago

I'm having same issue using @swc/core:1.5.2

tfeltwell commented 4 months ago

@throrin19 there is a deprecation warning against 1.5.2 now: @swc/core@1.5.2: Mac OS installation is broken. Upgrading to 1.5.3 fixes the issue for me (Bindings not found when running jest)

kdy1 commented 4 months ago

Can someone provide a minimal repro?

bediu commented 3 months ago

@kdy1

The installation always fails on certain servers. For me specifically, in the cheap ones running on vCPUs.

uname -m output is aarch64

lscpu output is:

Architecture:           aarch64
  CPU op-mode(s):       32-bit, 64-bit
  Byte Order:           Little Endian
CPU(s):                 4
  On-line CPU(s) list:  0-3
Vendor ID:              ARM
  Model name:           Neoverse-N1
    Model:              1
    Thread(s) per core: 1
    Core(s) per socket: 4
    Socket(s):          1
    Stepping:           r3p1
    BogoMIPS:           50.00
    Flags:              fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp ssbs

Let me know if I can provide you with nay additional information.

(We have resorted to version locking swc manually in our monorepo for now, which isn't good. )

nparoski commented 3 months ago

For those still struggling heres what worked for me

I've found a fix, apparently what happens (not sure why) is node_modules/@swc/core installs wrong optional packages within docker container.

Heres the fix:

Open docker image and find your WORKDIR Remove core-darwin-x64 or core-win-32-x64-msvc or similar from node_modules/@swc/core. There should be core-linux-x64-gnu and core-linux-x64-muscl (if your docker image is linux) Run npm install from within docker container (this time you should see correct packages in @swc/core under node_modules/) My understanding is that when you pull project and do npm install on host machine which is macOS or Windows, swc installs right packages for your host system.

I'm not sure why it skips installing correct ones on docker image but this is what causes issues. I tried setting this up on windows and macbook and both times had the same issues where this was the fix.

https://github.com/orgs/adonisjs/discussions/4600

LeonardoRochaInacio commented 1 month ago

If your problem is locally, I mean, you are using docker-compose pay attention to the shared volumes, probably it is sharing the wrong file between your windows system and your container running linux.

You can solve it excluding your node_modules from the sharing volumes from you docker-compose.yml file like this:

volumes:
      - ./:/home/node/app # Here we are sharing all the content from local to your container
      - /home/node/app/node_modules/ # Here we are excluding the node_modules