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

Bindings not found error #74

Closed
jjtfsalgado opened this issue Mar 24, 2023 · 52 comments
Closed

Bindings not found error #74

jjtfsalgado opened this issue Mar 24, 2023 · 52 comments

Comments

@jjtfsalgado
Copy link

jjtfsalgado commented Mar 24, 2023

Hey there

If you have this problem, you probably ran into is npm/cli#4828. The bug happens when npm generates the lockfile with an existing node_modules that contains platform-specific dependencies.

Two solutions:

  • Regenerate the lockfile from scratch rm -rf node_modules package-lock.json && npm i
  • Force install the optional dependencies of SWC:
npm install --force --save-optional \
        @swc/core \
        @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

Original post

Running vite we occasionally come across with this error. The way we found to overcome this was to remove node_modules and reinstall it. Do you guys have any ideas what is causing this?

Screenshot 2023-03-24 at 10 03 06

@ArnaudBarre
Copy link
Member

Hi!

I can't repro for now. Do you have any more info on when this happening?

This mostly like an install issue or an issue with SWC directly. What OS are you using?

@jiovanmichel
Copy link

Hello,
I have the same problem using
debian 10
typescript ^5.0.2
vite ^4.1.0

The problem it happens when run vite build or server.
The solution for me we has remove node_modules and install with yarn.

  • yarn install
  • yarn run dev (server vite)

@ArnaudBarre
Copy link
Member

Did this happen after an update of SWC?

@jiovanmichel
Copy link

jiovanmichel commented Mar 27, 2023

This happend after update typescript, the version @vitejs/plugin-react-swc is "^3.0.0"

@ArnaudBarre
Copy link
Member

That's strange I don't see any related issues on the SWC repo.
Did the issue reappear even after a clean install?

@jiovanmichel
Copy link

This happend after update typescript

That's strange I don't see any related issues on the SWC repo. Did the issue reappear even after a clean install?

I had a project
vite + react + typescript

I just updated the typescript to version 5

@SANTOrick
Copy link

Hey @ArnaudBarre.
To follow up on @jjtfsalgado, here is the machine specs:

OS: Microsoft 11
IDE: WebStorm 2022.3.2
VITE: 4.1.1
TS: 4.8.4

@ArnaudBarre
Copy link
Member

ArnaudBarre commented Mar 28, 2023

@SANTOrick so you got the error without TS 5?

Can people that have the issue also share their OS, node version and SWC installed version?

@skowrons
Copy link

skowrons commented Mar 29, 2023

OS: macOS Ventura 13.2 (Intel)
VITE: 4.2.1
TS: 4.9.3
PLUGIN-REACT-SWC: 3.2.0
NODE: 16.17.0

I got the same error. We have fixed the problem with running this command:

npm i -D @swc/cli @swc/core

In the end just installing swc as described here: https://swc.rs/docs/getting-started

@ArnaudBarre
Copy link
Member

What was the SWC version before and after re-intalling @swc/core?

@TeoSean00
Copy link

TeoSean00 commented Apr 6, 2023

The newly installed version of @swc/core that addresses this bug for me is "@swc/core": "^1.3.46", I did not have a before version prior to this, hope this helps!

@proddy
Copy link

proddy commented Apr 7, 2023

Probably unrelated but after updating I'm seeing
@vitejs/plugin-react-swc@npm:3.2.0 [f1d40] doesn't provide @swc/helpers (p84c25), requested by @swc/core

vite 4.2.1, swc/core 1.3.46, plugin-react-swc 3.2.0, OSX

@Tareq1586
Copy link

Running vite we occasionally come across with this error. The way we found to overcome this was to remove node_modules and reinstall it. Do you guys have any ideas what is causing this?

Screenshot 2023-03-24 at 10 03 06

Reinstalled but not working

@skowrons
Copy link

skowrons commented Apr 11, 2023

@ArnaudBarre here the previous and current versions after my command.

Before:
@swc/core = 1.3.41 (indirect dependency, we did not install it directly prior to this "fix")
@swc/cli is not currently installed

After:
@swc/core = 1.3.49
@swc/cli is not needed to fix the problem and can be ignored in the install command

@ArnaudBarre
Copy link
Member

@proddy This was a misconfiguration of peer dependencies, this is now fixed on the latest version

@Tareq1586 You still get the error with the latest version of @swc/core?

@Tareq1586
Copy link

npm i -D @swc/cli @swc/core

That worked for me.

@ArnaudBarre
Copy link
Member

@swc/cli should not be needed.npm i -D @swc/core will force a new version of @swc/core to be downloaded, but you can them remove it manually from the package.json because it's still a dependency of this plugin

@simeon-petrov-5
Copy link

Hi, just a quick bump - today we've encountered the same issue on a colleague's laptop. The interesting part is why this didn't fail on my machine for the last week or so ..

Updating @vitejs/plugin-react-swc to latest (eg. npm i -D @vitejs/plugin-react-swc@latest) fixed everything. No need to install swc locally (npm i -D @swc/cli @swc/core)

The culprit is actually Vite CLI. Creating a new project with npm create vite@latest or npm create vite@latest my-vue-app -- --template react-swc-ts uses the v3.0.0.

  "@vitejs/plugin-react-swc": "^3.0.0",
  "vite": "^4.2.0"

@ArnaudBarre
Copy link
Member

When starting out a new template, any package manager will install the latest version available (because of the ^ prefix).

I think there is just bad version of the SWC package that was published at some point and the solution is just to force a new version of @swc/core (direct or indirect by updating the plugin one)

@sjdemartini
Copy link

sjdemartini commented Apr 24, 2023

I ran into this same error when: (1) using my Mac to install all packages with yarn, (2) sharing the node_modules with a Docker image (which is running Debian), (3) running the vite server via Docker.

I never had this issue when using the babel-based https://github.com/vitejs/vite-plugin-react plugin. I also did not see this error when running the dev server directly from my Mac.

I was able to resolve it temporarily by opening a shell in the Docker image and running a yarn install, which pointed out that an OS-specific package was missing, which also resulted in a change to @swc/core:

➤ YN0000: ┌ Fetch step
➤ YN0013: │ @swc/core-linux-x64-gnu@npm:1.3.53 can't be found in the cache and will be fetched from the remote registry
➤ YN0000: └ Completed in 2s 456ms
➤ YN0000: ┌ Link step
➤ YN0008: │ esbuild@npm:0.17.18 must be rebuilt because its dependency tree changed
➤ YN0008: │ @swc/core@npm:1.3.53 [ba08b] must be rebuilt because its dependency tree changed

My .yarnrc.yml file was specifying the following, which was what esbuild docs point out should be used when sharing node_modules between platforms https://esbuild.github.io/getting-started/#simultaneous-platforms:

supportedArchitectures:
  os:
    - current
    - linux

But it turns out that's currently not sufficient for SWC swc-project/swc#2898. The workaround suggested there swc-project/swc#2898 (comment) of adding the following to supportedArchitectures did the trick, fixing the "Bindings not found" error and Docker-based vite server (no separate yarn install needed for Docker)!

supportedArchitectures:
  os:
    - current
    - linux
  libc:
    - current
    - glibc

@ArnaudBarre
Copy link
Member

@sjdemartini Yeah this is totally expected because SWC is using native binaries. supportedArchitectures is not a workaround, that the exact reason why this feature exist in yarn 2+ when using git shared node_modules.

@khaiquangnguyen
Copy link

khaiquangnguyen commented Apr 26, 2023

I just encountered this issue but it happens only very recently out of nowhere.
The issue happen when:

  • I run in a repo with cypress install
  • the errors appear for cypress spec files
  • happen only on ubuntu GH action server. no issue when run on MacOS locally. for GH action server, the errors appear for both docker and non-docker setup
  • running the babel-based plugin produces no issue

Edit: The issue is resolved after manually run npm install -D @swc/core. But before that, I tried to run npm install -D vite-plugin-react-swc@latest and the error still appears. Looks like manually forcing @swc/core is required.

@dearlordylord
Copy link

dearlordylord commented Apr 28, 2023

In case repro needed, I have just initialized a fresh project and encountered this issue. Exact commands from history is in README https://github.com/Firfi/vite-74-repro

in later commits, there's results of pnpm i -D @swc/cli @swc/core committed in

and then a result of rerun of pnpm install -D @swc/core which changes some files as well.

@tony19
Copy link

tony19 commented May 2, 2023

We noticed this problem after "refreshing" package-lock.json, which we do by deleting the file, and running npm install (node_modules not deleted beforehand). The result is npm removes all @swc/core-xxxx entries from the lockfile except the one for the current platform. This causes the Bindings not found error in Vite's dev server when that lockfile is then used in npm ci or npm install on another machine that isn't the same platform as the one that refreshed the lockfile.

See minimal reproduction in GitHub and StackBlitz.


The most reliable workaround I found is to force-install the optional dependencies of @swc/core as optional dependencies of your own project (only the dep that is supported on your platform is installed):

npm install --force --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

Then check the resulting lockfile into source control.

@ArnaudBarre
Copy link
Member

@tony19 Seems like a bug in npm. What version of npm are you using?

@tony19
Copy link

tony19 commented May 4, 2023

@ArnaudBarre npm v9.5.0, node v18.14.2

@ArnaudBarre
Copy link
Member

Wow just reproduced with npm 9.5.1. What a bug.
Found the issue in npm: npm/cli#4828
1 year old. They seems to don't care and ignore that people are using platform binaries nowdays. Even yarn v1 that is stale was updated to handle this correctly. Between pnpm new algorithm resolution, bun lockfile being totally unmaintainable, yarn v1 being stale, yarn v2 having so much config for simple things and this bug in npm I don't know what to recommend now.

@tony19
Copy link

tony19 commented May 4, 2023

Thanks for finding that issue. That's my exact scenario. I'll try spelunking npm source this weekend and submitting a PR if I can.

In the meantime, I think recommending installing the optional deps somewhere (README?) would be helpful.

@felipedev1996
Copy link

npm i -D @swc/cli @swc/core
instalé las dev dependencies npm i -D @swc/cli @swc/core ,pero el error continuaba, luego reinstalé node_modules y se solucionó.

@FossPrime
Copy link

FossPrime commented Jun 10, 2023

1-click reproduction: https://pr.new/github.com/FossPrime/vslite/tree/repro-swc

I'll submit a PR upstream to work around this

@FossPrime
Copy link

FossPrime commented Jun 10, 2023

PR got merged. I think the problem should be fix at this toolimg plugins level.

kat-tax/vslite#14
Heres what it took, 2 lines

one to detect web containers, one to import a fallback.

@masx200
Copy link

masx200 commented Jun 18, 2023

cnpm install --force --save-optional \
>         @swc/core \
>         @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

✖ Install fail! UnSupportedPlatformError: [@swc/core-darwin-arm64@1.3.64] skip download for reason darwin dont includes your platform android
UnSupportedPlatformError: [@swc/core-darwin-arm64@1.3.64] skip download for reason darwin dont includes your platform android
    at download (/data/data/com.termux/files/usr/lib/node_modules/cnpm/node_modules/.store/npminstall@7.9.0/node_modules/npminstall/lib/download/npm.js:285:17)
    at module.exports (/data/data/com.termux/files/usr/lib/node_modules/cnpm/node_modules/.store/npminstall@7.9.0/node_modules/npminstall/lib/download/npm.js:24:22)
    at async module.exports (/data/data/com.termux/files/usr/lib/node_modules/cnpm/node_modules/.store/npminstall@7.9.0/node_modules/npminstall/lib/download/index.js:19:10)
    at async _install (/data/data/com.termux/files/usr/lib/node_modules/cnpm/node_modules/.store/npminstall@7.9.0/node_modules/npminstall/lib/install_package.js:122:16)
    at async install (/data/data/com.termux/files/usr/lib/node_modules/cnpm/node_modules/.store/npminstall@7.9.0/node_modules/npminstall/lib/install_package.js:23:12)
    at async _installOne (/data/data/com.termux/files/usr/lib/node_modules/cnpm/node_modules/.store/npminstall@7.9.0/node_modules/npminstall/lib/local_install.js:215:15)
    at async mapper (/data/data/com.termux/files/usr/lib/node_modules/cnpm/node_modules/.store/npminstall@7.9.0/node_modules/npminstall/lib/local_install.js:140:5)
npminstall version: 7.9.0
npminstall argv: /data/data/com.termux/files/usr/bin/node /data/data/com.termux/files/usr/lib/node_modules/cnpm/node_modules/.store/npminstall@7.9.0/node_modules/npminstall/bin/install.js --fix-bug-versions --china --userconfig=/data/data/com.termux/files/home/.cnpmrc --disturl=https://cdn.npmmirror.com/binaries/node --registry=https://registry.npmmirror.com --force --save-optional @swc/core @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

@FossPrime
Copy link

cnpm install --force --save-optional \
>         @swc/core \
>         @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

✖ Install fail! UnSupportedPlatformError: [@swc/core-darwin-arm64@1.3.64] skip download for reason darwin dont includes your platform android
UnSupportedPlatformError: [@swc/core-darwin-arm64@1.3.64] skip download for reason darwin dont includes your platform android
    at download (/data/data/com.termux/files/usr/lib/node_modules/cnpm/node_modules/.store/npminstall@7.9.0/node_modules/npminstall/lib/download/npm.js:285:17)
    at module.exports (/data/data/com.termux/files/usr/lib/node_modules/cnpm/node_modules/.store/npminstall@7.9.0/node_modules/npminstall/lib/download/npm.js:24:22)
    at async module.exports (/data/data/com.termux/files/usr/lib/node_modules/cnpm/node_modules/.store/npminstall@7.9.0/node_modules/npminstall/lib/download/index.js:19:10)
    at async _install (/data/data/com.termux/files/usr/lib/node_modules/cnpm/node_modules/.store/npminstall@7.9.0/node_modules/npminstall/lib/install_package.js:122:16)
    at async install (/data/data/com.termux/files/usr/lib/node_modules/cnpm/node_modules/.store/npminstall@7.9.0/node_modules/npminstall/lib/install_package.js:23:12)
    at async _installOne (/data/data/com.termux/files/usr/lib/node_modules/cnpm/node_modules/.store/npminstall@7.9.0/node_modules/npminstall/lib/local_install.js:215:15)
    at async mapper (/data/data/com.termux/files/usr/lib/node_modules/cnpm/node_modules/.store/npminstall@7.9.0/node_modules/npminstall/lib/local_install.js:140:5)
npminstall version: 7.9.0
npminstall argv: /data/data/com.termux/files/usr/bin/node /data/data/com.termux/files/usr/lib/node_modules/cnpm/node_modules/.store/npminstall@7.9.0/node_modules/npminstall/bin/install.js --fix-bug-versions --china --userconfig=/data/data/com.termux/files/home/.cnpmrc --disturl=https://cdn.npmmirror.com/binaries/node --registry=https://registry.npmmirror.com --force --save-optional @swc/core @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

I can reproduce this error on Termux from FreeDroid. Nestbox registers as linux-arm64, while termux requires android-arm64 builds. In Go this is an easy thing to fix... and I've
made rust builds on Termux many times before, both lvm and on device.

Termux on Pixel 7:
Screenshot_20230618-112638

Nestbox for Pixel 7 running Debian:
Screenshot_20230618-112325

@mehrdad-kj
Copy link

mehrdad-kj commented Jun 27, 2023

finally what we should do to solve this error? when ever i pull a branch i got this error and to fix it i havt to delete node-modules and yarn install to fix it. and some packages dont get install well after this. like redux toolkit

@benduran
Copy link

benduran commented Jun 27, 2023

I can confirm I'm experiencing this on an M2 mac. Interestingly enough, I notice data corruption warnings coming from my company's JFrog Artifactory instance, which acts as a reverse proxy out to the NPMJS registry. Was a corrupted build of the SWC Plugin pushed out at some point?

npm WARN tar zlib: invalid block type
npm WARN tarball tarball data for @swc/core-darwin-arm64@https://my-artifactory-url.com/api/npm/npm-my-company/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.66.tgz (sha512-UijJsvuLy73vxeVYEy7urIHksXS+3BdvJ9s9AY+bRMSQW483NO7RLp8g4FdTyJbRaN0BH15SQnY0dcjQBkVuHw==) seems to be corrupted. Trying again.
npm WARN tar zlib: invalid block type
npm WARN tarball tarball data for @swc/core-darwin-arm64@https://my-artifactory-url.com/api/npm/npm-my-company/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.66.tgz (sha512-UijJsvuLy73vxeVYEy7urIHksXS+3BdvJ9s9AY+bRMSQW483NO7RLp8g4FdTyJbRaN0BH15SQnY0dcjQBkVuHw==) seems to be corrupted. Trying again.

For those that are still stuck

Try using the standard @vitejs/plugin-react plugin instead. Falling back to that from the SWC plugin has unblocked me for now:

// vite.config.ts

import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  server: {
    port: 3000,
  },
});

@mehrdad-kj
Copy link

clone the repo could be a temp solution.

@orangejava
Copy link

OS: macOS Ventura 13.2 (Intel) VITE: 4.2.1 TS: 4.9.3 PLUGIN-REACT-SWC: 3.2.0 NODE: 16.17.0

I got the same error. We have fixed the problem with running this command:

npm i -D @swc/cli @swc/core

In the end just installing swc as described here: https://swc.rs/docs/getting-started

my issues:
👽 Taro v3.5.1

Error: Bindings not found
at Compiler.transformSync (/node_modules/@swc/core/index.js:249:15)

when start the taro project, it has been this error, when I run 'npm i -D @swc/cli @swc/core', the issue has been solved. Thank you for your answer.

@space1worm
Copy link

I have exact same problem... error message : bindings not found

@ChamuMutezva
Copy link

I couldn't find a solution for Bindings not found when using plugin-react-swc as in the following vite config file

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
})

Initial the project worked well in my previous laptop but has been failling on my current one and having tried the recommendations posted here , the results was the same. My temporary solution for now was to:

  1. replace "@vitejs/plugin-react-swc": "^3.0.0", in the package.json with "@vitejs/plugin-react": "^4.0.0",
  2. delete package-lock.json
  3. delete node_modules
  4. replace the vite.config file with the following
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
})
  1. npm install

@n-ce
Copy link

n-ce commented Jul 25, 2023

Termux on Pixel 7: Screenshot_20230618-112638

My Installation is same as these except mine is armv7 so it shows armeabi not found and uses the fallback. Then it results to these if anything wrong happened either during installation or change in project files.
Screenshot_20230725-182300_Chrome

@Yzzzed
Copy link

Yzzzed commented Aug 23, 2023

Now the lastest version of @vitejs/plugin-react-swc is 3.3.2, but this problem still happen, can anybody tell me what should I do to solve this error? well I know I can use @vitejs/plugin-react intend, but I just wanna use swc.

go https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170 and download the [ Visual Studio 2015, 2017, 2019, and 2022 ], I try to download x64 version, then remove node_modules and reinstall, it works for me.

@vaynevayne
Copy link

@erkanisuf
Copy link

Why this issue is closed? I am getting same error with latest vite.

@LumioDA
Copy link

LumioDA commented Nov 29, 2023

OS: macOS Ventura 13.2 (Intel) VITE: 4.2.1 TS: 4.9.3 PLUGIN-REACT-SWC: 3.2.0 NODE: 16.17.0

I got the same error. We have fixed the problem with running this command:

npm i -D @swc/cli @swc/core

In the end just installing swc as described here: https://swc.rs/docs/getting-started

I just wanted to let you know that it works for me. Using a Macbook Pro on MacOS Sonoma 14.1.1 with Intel processor

@harsh-leen
Copy link

Getting this same error. Weirdly enough it behaves differently based on the base docker image of bun. On Apple silicon(arm arch) with Docker desktop.

SWC doesn't work with: oven/bun:1-alpine
SWC works with: oven/bun:1

@Basovs
Copy link

Basovs commented Jan 23, 2024

Had same issue. Come from nowhere. Was actively working on the project and suddenly i got this error.

Params

  • Macbook Apple Silicon M2
  • Turborepo
  • Vite
  • React
  • npm

Fixed by:
Deleting the "package-lock.json" file and all "node_modules" folders. and then reinstall.

Just make sure that by deleting the "package-lock.json" and reinstalling doesn't break your dependencies by unintentionally installing/updating to major package versions.

@kaungpyaesoneaunggic
Copy link

npm update worked for me with similar scenarios. Don't knonw if already answered though.

@ChronosXBT
Copy link

ChronosXBT commented Mar 13, 2024

for Android arm64 use this command
pnpm add --save-optional @swc/core-android-arm64

or if you use npm
npm install --save-optional @swc/core-android-arm64

keep in mind that this package hasn't been updated in a while, at the time of writing this comment, latest swc core package version is 1.4.7 while swc/core-android-arm64 package version is 1.3.11

but atleast it works

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

No branches or pull requests