Apple Silicon ESBUILD Error when building advanced cannister projects

Looking for ICP developers who are using Apple silicon to help me with this stubborn problem.

I have pulled this fullstack project from Github: GitHub - rvanasa/vite-react-motoko: Starter project for Vite + React + TypeScript + Motoko

and double checked that my OSX, nodjs, npm, and dfx are all running the latest versions. When I enter the command >npm run setup, I always get this crash:

Deploying all canisters.

All canisters have already been created.

Building canisters…

Building frontend…

Error: Failed while trying to deploy canisters.

Caused by: Failed while trying to deploy canisters.

Failed to build all canisters.

Failed while trying to build all canisters.

The post-build step failed for canister ‘bd3sg-teaaa-aaaaa-qaaba-cai’ (frontend) with an embedded error: Failed to build frontend for network ‘local’.: The command ‘cd “/Users/none/VSCode/websites/icp” && BACKEND_CANISTER_ID=“bkyz2-fmaaa-aaaaa-qaaaq-cai” CANISTER_CANDID_PATH=“/Users/none/VSCode/websites/icp/.dfx/local/canisters/frontend/assetstorage.did” CANISTER_CANDID_PATH_BACKEND=“/Users/none/VSCode/websites/icp/.dfx/local/canisters/backend/backend.did” CANISTER_CANDID_PATH_backend=“/Users/none/VSCode/websites/icp/.dfx/local/canisters/backend/backend.did” CANISTER_ID=“bd3sg-teaaa-aaaaa-qaaba-cai” CANISTER_ID_BACKEND=“bkyz2-fmaaa-aaaaa-qaaaq-cai” CANISTER_ID_FRONTEND=“bd3sg-teaaa-aaaaa-qaaba-cai” CANISTER_ID_backend=“bkyz2-fmaaa-aaaaa-qaaaq-cai” CANISTER_ID_frontend=“bd3sg-teaaa-aaaaa-qaaba-cai” DFX_NETWORK=“local” DFX_VERSION=“0.15.3” FRONTEND_CANISTER_ID=“bd3sg-teaaa-aaaaa-qaaba-cai” “npm” “run” “build”’ failed with exit status ‘exit status: 1’.

Stdout:

vite-react-motoko@0.0.0 build

tsc && vite build

Stderr:

failed to load config from /Users/none/VSCode/websites/icp/vite.config.ts

error during build:

Error:

You installed esbuild for another platform than the one you’re currently using.

This won’t work because esbuild is written with native code and needs to

install a platform-specific binary executable.

Specifically the “@esbuild/darwin-arm64” package is present but this platform

needs the “@esbuild/darwin-x64” package instead. People often get into this

situation by installing esbuild with npm running inside of Rosetta 2 and then

trying to use it with node running outside of Rosetta 2, or vice versa (Rosetta

2 is Apple’s on-the-fly x86_64-to-arm64 translation service).

If you are installing with npm, you can try ensuring that both npm and node are

not running under Rosetta 2 and then reinstalling esbuild. This likely involves

changing how you installed npm and/or node. For example, installing node with

the universal installer here should work: Node.js — Download. Or

you could consider using yarn instead of npm which has built-in support for

installing a package on multiple platforms simultaneously.

If you are installing with yarn, you can try listing both “arm64” and “x64”

in your “.yarnrc.yml” file using the “supportedArchitectures” feature:

Keep in mind that this means multiple copies of esbuild will be present.

Another user posted about this previously (Esbuild on macOs M1 (apple chip)) but the solution he provided did not work for me. Reaching out to all apple arm devs for help!

Simple ICP cannisters run fine for me using the dfx deploy command, but any project which contains the esbuild node_module always throws this error and I have been trying to fix it all damn day.

I tried cloning your project and could not get that to work either. How did you get past the error message I posted on your m1 Mac?

I just resized your issue is different, Im not know about vite-react-motoko, I was using rust. Maybe someone else will help. Try to join this some dfinity office hours on discord . And post the solution here to help others as well.

I will make a YouTube video on it if someone helps me

can I see your youtube channel ?

this forum account has my real name on it and I am wanting to keep the YouTube channel anonymous, I will send a dm

Try running node -p “process.arch”. If not arm64, uninstall nodejs and reinstall it through Homebrew.

just in case, do you have rosetta installed in your system?

wobbles head side to side in irritating rhythm

facing the same issue