vite-plugin-react-swc: Bindings not found error
Hey there
If you have this problem, you probably ran into is https://github.com/npm/cli/issues/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?
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 25
- Comments: 52 (12 by maintainers)
Commits related to this issue
- chore(deps): install `swc` dev dependencies https://github.com/vitejs/vite-plugin-react-swc/issues/74#issuecomment-1488694882 — committed to lemredd/markdown-previewer by lemredd a year ago
- chore(deps): reuse `@vitejs/plugin-react` https://github.com/vitejs/vite-plugin-react-swc/issues/74#issuecomment-1610364954 — committed to lemredd/markdown-previewer by lemredd a year ago
- test: applied fix suggested from https://github.com/vitejs/vite-plugin-react-swc/issues/74 — committed to RahulARanger/handshake by RahulARanger 2 months ago
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:
In the end just installing swc as described here: https://swc.rs/docs/getting-started
@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?
Yes, this is https://github.com/npm/cli/issues/4828. The bug happens when npm generates the lockfile with an existing
node_modules
that contains platform-specific dependencies. Solution should in all cases be to generate whilenode_modules
does not exist:I would close and pin this issue in the repo.
That worked for me.
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?
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:1-click reproduction: https://pr.new/github.com/FossPrime/vslite/tree/repro-swc
I’ll submit a PR upstream to work around this
@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.I ran into this same error when: (1) using my Mac to install all packages with
yarn
, (2) sharing thenode_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
:My
.yarnrc.yml
file was specifying the following, which was whatesbuild
docs point out should be used when sharing node_modules between platforms https://esbuild.github.io/getting-started/#simultaneous-platforms:But it turns out that’s currently not sufficient for SWC https://github.com/swc-project/swc/issues/2898. The workaround suggested there https://github.com/swc-project/swc/issues/2898#issuecomment-1180845472 of adding the following to
supportedArchitectures
did the trick, fixing the “Bindings not found” error and Docker-based vite server (no separateyarn install
needed for Docker)!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
ornpm create vite@latest my-vue-app -- --template react-swc-ts
uses the v3.0.0.Had same issue. Come from nowhere. Was actively working on the project and suddenly i got this error.
Params
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.
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
Why this issue is closed? I am getting same error with latest vite.
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.
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
PR got merged. I think the problem should be fix at this toolimg plugins level.
https://github.com/kat-tax/vslite/pull/14 Heres what it took, 2 lines
one to detect web containers, one to import a fallback.
Thanks everyone for helping on this. Please go like the npm issue.
See the updated initial comment for solutions to workaround this.
Same issue here. Tried
npm install -D @swc/core
andnpm install -D vite-plugin-react-swc@latest
as someone mentioned up. But it is not working for me.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.
We noticed this problem after “refreshing”
package-lock.json
, which we do by deleting the file, and runningnpm install
(node_modules
not deleted beforehand). The result isnpm
removes all@swc/core-xxxx
entries from the lockfile except the one for the current platform. This causes theBindings not found
error in Vite’s dev server when that lockfile is then used innpm ci
ornpm 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):Then check the resulting lockfile into source control.
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)@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 pluginReinstalled but not working