swc-project / swc

Rust-based platform for the Web
https://swc.rs
Apache License 2.0
30.93k 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 2 years ago

Which os/cpu are you using?

kdy1 commented 2 years ago

Also, did you use something like --skip-optional or --ignore-scripts?

sebastianrath commented 2 years ago

Thanks for the quick reply! I added more information under System Info. No --skip-optional nor --ignore-scripts is used.

Also for completeness, here is the definition of npm run test in package.json:

"test": "nyc --reporter=html --reporter=lcov --reporter=text ava"
sebastianrath commented 2 years ago

Quick update, the same project/commit successfully built on the same machine (also Parallels) under Windows. Updating to swc/core@1.42.0works now also under Linux. Could the error come back or did the latest version fix something that could explain the issue on Linux?

kdy1 commented 2 years ago

Did you share the project directory? You should install on target platform unless you are overriding npm config

ejkg commented 2 years ago

I was able to reproduce this issue with my Apollo Federation Gateway running in a Node docker container. I can provide the Dockerfile.

FROM node:17.3
WORKDIR /app
ENV NODE_ENV=dev
ENV ZIPKIN=http://localhost:9411
EXPOSE 4000
COPY . .
CMD ["yarn", "run", "dev"]

Also important to note is that I'm not experiencing this issue when I run this directly on my machine. macOS 12.5.1, Apple Silicon M1 node 17.3.1

encountered this error on docker run my-image:1.0

$ docker run my-image:1.0
yarn run v1.22.17

$ ts-node src/index.ts
/app/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 (/app/node_modules/ts-node/src/transpilers/swc.ts:262:13)
    at createSwcOptions (/app/node_modules/ts-node/src/transpilers/swc.ts:211:25)
    at create (/app/node_modules/ts-node/src/transpilers/swc.ts:56:41)
    at createTranspiler (/app/node_modules/ts-node/src/index.ts:784:16)
    at createTranspileOnlyGetOutputFunction (/app/node_modules/ts-node/src/index.ts:1341:28)
    at createFromPreloadedConfig (/app/node_modules/ts-node/src/index.ts:1404:34)
    at phase4 (/app/node_modules/ts-node/src/bin.ts:543:44)
    at bootstrap (/app/node_modules/ts-node/src/bin.ts:95:10)
    at main (/app/node_modules/ts-node/src/bin.ts:55:10)
    at Object.<anonymous> (/app/node_modules/ts-node/src/bin.ts:800:3)
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.

fwiw I'm running this

    "@swc/core": "^1.2.245",
    "@swc/helpers": "^0.4.8",
Bluzzi commented 2 years ago

I have the same problem, I can't start my project at all with Docker/TS-Node/SWC

RiESAEX commented 2 years ago

Can you try to reinstall swc in your docker?

Bluzzi commented 2 years ago

That's what I am doing

Dockerfile:

FROM node:16.16-alpine

WORKDIR /app

COPY package*.json ./
RUN npm install
COPY . .

CMD npm run start

.dockerignore:

node_modules
swc-bot commented 2 years ago

This issue has been automatically closed because it received no activity for a month and had no reproduction to investigate. If you think this was closed by accident, please leave a comment. If you are running into a similar issue, please open a new issue with a reproduction. Thank you.

Bluzzi commented 2 years ago

This issue is still valid

btecu commented 2 years ago

I'm also running into this issue after updating from node 14.17.1 to node 16.16.0 on a MBP 16 M1 Pro:

/Users/.../node_modules/@swc/core/index.js:250
        throw new Error("Bindings not found");
        ^

Error: Bindings not found
    at Compiler.transformSync (/Users/.../node_modules/@swc/core/index.js:250:15)
    at transformSync (/Users/.../node_modules/@swc/core/index.js:348:21)
    at transformSync (/Users/.../node_modules/@swc-node/core/index.ts:69:26)
    at compile (/Users/.../node_modules/@swc-node/register/register.ts:44:40)
    at exts (/Users/.../node_modules/@swc-node/register/register.ts:55:38)
    at Module._compile (/Users/.../node_modules/pirates/lib/index.js:130:29)
    at Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
    at Object.newLoader [as .ts] (/Users/.../node_modules/pirates/lib/index.js:141:7)
    at Module.load (node:internal/modules/cjs/loader:1004:32)
    at Function.Module._load (node:internal/modules/cjs/loader:839:12)
swc-bot commented 1 year ago

This issue has been automatically closed because it received no activity for a month and had no reproduction to investigate. If you think this was closed by accident, please leave a comment. If you are running into a similar issue, please open a new issue with a reproduction. Thank you.

btecu commented 1 year ago

The issue is still valid.

kwonoj commented 1 year ago

Not sure why bot aggressively marks this one 🤔

jgujgu commented 1 year ago

@btecu @Bluzzi My co-worker found a fix for this, inside .yarnrc.yml. Both of us are using M1 Pro MacBook Pros and his worked without this addition, but for some reason mine had the error throw new Error("Bindings not found");

The solution was to put - arm64 under cpu. Full output of .yarnrc.yml.

nodeLinker: node-modules

plugins:
  - path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
    spec: "@yarnpkg/plugin-workspace-tools"

yarnPath: .yarn/releases/yarn-3.2.3.cjs

# This setting ensures we always install the Linux binaries when running `yarn install`. This is needed for running
# swc natively in Docker from a Mac host.
supportedArchitectures:
  os:
    - current
    - linux
  cpu:
    - current
    - x64
    - arm64
  libc:
    - current
    - glibc

I don't know if it'll solve your guy's problems, but it did solve mine!

btecu commented 1 year ago

Thanks @jgujgu. Is there anything for npm?

jgujgu commented 1 year ago

@btecu I really wouldn't know, sorry...you really just have to make sure the correct binaries are installed. I imagine npm would have a similar config or way to declare it.

gspetrou commented 1 year ago

Getting this error on an M1 Mac using node 19, but not on 18.

jcampbell05 commented 1 year ago

I'm getting this issue with the Node 16 docker image - the yarn fix didn't solve it.

wodCZ commented 1 year ago

I've ran into similar issue with a bit uncommon setup, but maybe this will help shed some light.

I have a working setup on local node 18, using yarn (on intel mac). I wanted to create a sample Dockerfile using npm, so I ran npm i locally to generate package-lock.json. Then docker build ran up to the build point where it failed on Fallback bindings does not support filesystem access.. When installing @swc/core and @swc-cli in the build step in the container again, it worked well.

Then I removed node_modules and package-lock.json on the host and ran npm i again to get a new package-lock.json. And with this new lock the whole build ran successfully.

old-package-lock.json.txt package-lock.json.txt

When compared, there are few @swc packages that didn't get "locked" with existing node_modules.

So, maybe the "work-around" is to rm -rf node_modules && rm package-lock.json && npm i on the host?

Also, on host I have cli, core, core-darwin-x64 in node_modules/@swc. When I ran ls in the broken-build image, I got cli, core, wasm with the old-package-lock.json. With the new, working lock I have core-linux-x64-gnu and core-linux-x64-musl in there instead. Docker image is based on node:18-slim.

jcampbell05 commented 1 year ago

My issue was because I was mounting a volume in such a way the node_modules would be mounted to the host which could cause issues.

By adding node_modules in it's own volume in the docker-compose spec I can tell docker to preserve the node_modules folder from the underlying image and now it works.

ZuBB commented 1 year ago

Hi there!

I also had this issue and was able to resolve it. below are my "story".

Most beneficial (give me some food to think) to me were messages from @jgujgu and @wodCZ.

I was migrating from yarn to npm, and I wanted to have a dependency tree as similar as possible. So I did not delete node_modules folder and just run npm i. This caused package-lock.json file to be not fully valid, where swc package for my arch was missing (I figured out that later). So I did a couple of test setups, and they were OK. At some point, I decided to check "moving parts" of the swc software in the file system and found that arm64 file/package was missing.


Summary: if you got a subject error message -- make sure you have both arch package and arch binary in your FS

Advice to developers: maybe you should add/adjust a check if arch binary exists and make sure the error message for that is crystal clear

Trojan0523 commented 1 year ago

using node v16.18.1 also met this problem, on MBP 13 M1, problem performed like @btecu

Error: Bindings not found at Compiler.transformSync (/Users/buxiongyu/Desktop/zeus/node_modules/.pnpm/@swc+core@1.3.20/node_modules/@swc/core/index.js:250:15) at Object.transformSync (/Users/buxiongyu/Desktop/zeus/node_modules/.pnpm/@swc+core@1.3.20/node_modules/@swc/core/index.js:348:21) at compile (/Users/buxiongyu/Desktop/zeus/nodemodules/.pnpm/@swc+register@0.1.10@swc+core@1.3.20/node_modules/@swc/register/lib/node.js:76:22) at compileHook (/Users/buxiongyu/Desktop/zeus/nodemodules/.pnpm/@swc+register@0.1.10@swc+core@1.3.20/node_modules/@swc/register/lib/node.js:91:16) at Module._compile (/Users/buxiongyu/Desktop/zeus/node_modules/.pnpm/pirates@4.0.5/node_modules/pirates/lib/index.js:130:29) at Module._extensions..js (node:internal/modules/cjs/loader:1209:10) at Object.newLoader [as .js] (/Users/buxiongyu/Desktop/zeus/node_modules/.pnpm/pirates@4.0.5/node_modules/pirates/lib/index.js:141:7) at Module.load (node:internal/modules/cjs/loader:1033:32) at Function.Module._load (node:internal/modules/cjs/loader:868:12) at Module.require (node:internal/modules/cjs/loader:1057:19)

i'm just wondering if it is cross platform problem of npm/pnpm ?

DzmVasileusky commented 1 year ago

Same issue on

   MacBook Pro (Retina, 15-inch, Mid 2014)
   OS   : darwin x64
   Node : 16.15.0
   npm  : 8.10.0

Experience this while using @nrwl/nx npm package.

DzmVasileusky commented 1 year ago

What have helped me

  1. Create new clean project
  2. manually install @swc/core of needed version there
  3. manually copypaste core-darwin-x64 to node_modules/@swc
nephix commented 1 year ago

What helped me in my npm monorepo:

  1. npm uninstall all swc related packages
  2. remove package-lock.json
  3. remove all node_modules directories
  4. npm install
  5. npm install the swc related packages again
roftLin commented 1 year ago

Hey buddy, I have encountered the same issue as you and have solved it, I would like to share my experience with you to see if it can help. Just a few days ago I was able to install Taro-cli without any issues, then after reinstalling the system, my project encountered the same error as yours. I searched for solutions in the Taro repository and the SWC repository, but there was no ready answer. However, they gave some directions to troubleshoot.So I tried switching the node version, package manager version and source, and Taro/cli version, but all failed. Finally, I debugged the source code with breakpoints, combined with my own experience, and found that the problem was related to the rust runtime environment, which needed to be installed. The specific installation method can be referred to the link below. https://blog.csdn.net/u011149152/article/details/123518465

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.

arxpoetica commented 1 year ago

@littleski I ran into the same problem and adding @swc/wasm solved it for me too...so yes, a bug in the post install maybe?

pbredenberg commented 1 year ago

I ran into a similar problem when running a build with SWC in GitHub actions (worked fine on my M1 mac).

The build would fail with Fallback bindings does not support filesystem access.

After upgrading @swc/cli to 0.1.62 and @swc/core to 1.3.39 the build executed again in my workflow.

taltul-simplex commented 1 year ago

What helped me in my npm monorepo:

  1. npm uninstall all swc related packages
  2. remove package-lock.json
  3. remove all node_modules directories
  4. npm install
  5. npm install the swc related packages again

This is exactly what I did and it solved the issue.

TIMMLOPK commented 1 year ago

I have the same issue when I use Github action on @swc/core 1.3.44. I try to downgrade to @swc/core 1.3.39.The action work again.

aleczratiu commented 1 year ago

What have helped me

  1. Create new clean project
  2. manually install @swc/core of needed version there
  3. manually copypaste core-darwin-x64 to node_modules/@swc

Indeed this solution is working well when I run npx jest "file", btw installing @swc/core is enough and solves the problem, but I'm Interested if there are other dependencies that require it.

2b1q commented 1 year ago

M1, node v18.12.1, pnpm (solved) before I added @swc/core-linux-arm64-musl as dev deps, had same err

  ● Test suite failed to run
    Bindings not found
      at Compiler.transformSync (node_modules/.pnpm/@swc+core@1.3.40/node_modules/@swc/core/index.js:250:15)
mmatila commented 1 year ago

Having similar issues here.

M1 Pro node v19.7.0 (tried various previous versions as well) @swc/jest ^0.2.26

Error: Jest: Got error running globalSetup - /app/tests/globalSetup.ts, reason: Bindings not found

at Compiler.transformSync (/node_modules/@swc/core/index.js:250:15)

Tried going through the whole install/uninstall process with swc packages and node_modules that seemed to work for some people in the thread – not for me.

Edit: Tried the install/uninstall process once more and it ended up fixing things 👍🏽

DzmVasileusky commented 1 year ago

this issue is annoying I have to install swc manually each time after npm i, does anybody found a way to fix it once for all?

kwonoj commented 1 year ago

Primarily this is due to you have installed one binaries for the specific platform and tries to run on other platform which doesn't have corresponding binary. Upstream issues like https://github.com/npm/cli/issues/4828 make things more challenging.

We are open to accept fixes, but I don't believe there's no quick win for now.

DzmVasileusky commented 1 year ago

@kwonoj well, we are sharing project among people with MacOS, Windows, Ubuntu but this is a normal situation when repo has collaborators

kwonoj commented 1 year ago

I'm not saying it's uncommon to share project across different platform users, saying there are some constraint of actions we can take. As said, we are open to accept fix / suggestions but afaik there is no clear win to any paths we can take.

DaSchTour commented 1 year ago

I think that the approach how bindings are handled is not compatible to package-lock.json and npm ci. When installing (generating package-lock) on one OS and running the CI task on another OS by using npm ci this will always fail because the wrong bindings are persisted in the package-lock.

Or maybe it's because swc doesn't use the expected postinstall scripts or so that would work with the recommended approach when using private repositories on a CI like described in this documentation: https://github.com/actions/setup-node/blob/main/docs/advanced-usage.md#use-private-packages

In short when using npm ci --ignore-scripts for security reasons swc doesn't setup properly when running npm rebuild && npm run prepare --if-present afterwards.

DzmVasileusky commented 1 year ago

We switched to pnpm, it is not only faster it also doesn't have this issue as well as issues with legacy peer dependencies in lock file

moltar commented 1 year ago

Having the same issue. The only solution is to completely nuke the nvm (fnm) Node environment, and the local node_modules and do a full re-install. Seems like something gets written into the global scope, that has an effect on this?

moltar commented 1 year ago

Never mind, just did it again without node (nvm) nuking, just node_modules and it worked.

For us, the cause of this misalignment, I think, is Renovate Bot. Every time it updates a dep, and I do a pull, then the breakage will occur.

SkyaTura commented 1 year ago

Same problem. Runs fine on MacOS in local env and throws while building on Docker.


The workaround is use pnpm. It is not desired on our project but it passes...

SkyaTura commented 1 year ago

pnpm solved the build on CI, but my coworker is unable to run the project on Ubuntu (Node v18.16.0)

jaybe78 commented 1 year ago

Getting same issue. pnpm does not work for me

jaybe78 commented 1 year ago
Screenshot 2023-07-25 at 09 34 33

What the hell ?

kdy1 commented 1 year ago

@jaybe78 https://kdy1.dev/posts/2023/1/plus-1-is-spam

jaybe78 commented 1 year ago

@kdy1 Well sorry if my comment is totally useless but that issue is still valid ! is it being worked on or are we supposed to accept that pnpm workaround ?