Esbuild on macOs M1 (apple chip)

dfx deploy frontend cuses this issue

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 'bw4dl-smaaa-aaaaa-qaacq-cai' (frontend) with an embedded error: Failed to build frontend for network 'local'.: The command '"npm" "run" "build"' failed with exit status 'exit status: 1'.
Stdout:

> dfn-react-ts@0.1.3 prebuild
> dfx generate


> dfn-react-ts@0.1.3 build
> vite build


Stderr:
Generating type declarations for canister user_canister:
  src/declarations/user_canister/user_canister.did.d.ts
  src/declarations/user_canister/user_canister.did.js
  src/user_canister/user_canister.did
Generating type declarations for canister frontend:
  src/declarations/frontend/frontend.did.d.ts
  src/declarations/frontend/frontend.did.js
  src/declarations/frontend/frontend.did
failed to load config from /Users/ahmed/Desktop/odoc/vite.config.js
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: https://nodejs.org/en/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:
https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
Keep in mind that this means multiple copies of esbuild will be present.

Another alternative is to use the "esbuild-wasm" package instead, which works
the same way on all platforms. But it comes with a heavy performance cost and
can sometimes be 10x slower than the "esbuild" package, so you may also not

my system ifo

$ dfx --version
dfx 0.14.3
$ node -v
v18.17.0

macbook pro m1

Not sure what you are building.
Try npm uninstall esbuild
and then npm install esbuild that should get the proper package.

My best guess would be: if you run npm install from within your IDE/different terminal than dfx deploy there’s a risk that one command is run with Rosetta emulation and one without.

Solved:
by runing sh -ci "$(curl -fsSL https://internetcomputer.org/install.sh)"