Failed: error occurred while running build command: wasm-pack: not found

For Workes & Pages, what is the name of the domain?

ear-training.pages.dev

What is the error message?

19:15:41.769 Executing user command: npm run build 19:15:42.309 19:15:42.310 > [email protected] build 19:15:42.310 > cd wasm && wasm-pack build --target web && cd … && tsc && vite build 19:15:42.310 19:15:42.318 sh: 1: wasm-pack: not found 19:15:42.327 Failed: Error while executing user command. Exited with error code: 127 19:15:42.338 Failed: build command exited with code: 1 19:15:43.414 Failed: error occurred while running build command

What is the issue or error you’re encountering

Cloudflare Pages app that relies on wasm fails to build

What steps have you taken to resolve the issue?

Is wasm just not supported in Cloudflare Pages? I see this example repo that shows wasm being used in Pages Functions (GitHub - cloudflare/pages-fns-with-wasm-demo), but I don’t need Functions or Workers (this app runs entirely in the user’s browser). Should I just pre-build my wasm package and check it into my git repo rather than asking Cloudflare Pages to build it from source?

What are the steps to reproduce the issue?

  1. Create a Cloudflare Pages app whose build step requires running wasm-pack build
  2. Trigger a deployment

Is wasm-pack a part of your npm packages that get installed on build?

1 Like

d’oh this was it. I’d installed wasm-pack globally on my local machine rather than my devDependencies.

For anyone else who runs into this, I had to do the following to get wasm-pack build working:

  1. Add wasm-pack to my project’s devDependencies: npm install -D wasm-pack
  2. Tell Cloudflare to install cargo as part of the build process (necessary to run wasm-pack build)
    a. Create a new cloud_build.sh script in my repo with the following contents:
set -ex
curl https://sh.rustup.rs -sSf | sh -s -- -y && . "$HOME/.cargo/env"
wasm-pack build --target web wasm
b. Make `cloud_build.sh` 
c. Add a new `build:cloud` script in `package.json`

Huh, looks like the Markdown formatting is a little wonky; those last two lines should read:

b. Make cloud_build.sh executable: chmod +x ./cloud_build.sh
c. Add a new build:cloud script in package.json: "build:cloud": "./cloud_build.sh && npm run build"

Thanks @Cyb3r-Jak3!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.