Skip to content

fix(model-driver-mediapipe): serve wasm assets from public/ to fix production 404#1509

Open
lietblue wants to merge 2 commits intomoeru-ai:mainfrom
lietblue:mediapipe-vision-wasm-res-fix
Open

fix(model-driver-mediapipe): serve wasm assets from public/ to fix production 404#1509
lietblue wants to merge 2 commits intomoeru-ai:mainfrom
lietblue:mediapipe-vision-wasm-res-fix

Conversation

@lietblue
Copy link
Copy Markdown
Collaborator

Summary

  • Fix GET /assets/assets/wasm/vision_wasm_internal.js 404 error when running vite build && vite preview for stage-web
  • Root cause: new URL('./assets/wasm', import.meta.url) is a directory reference that Vite does not rewrite in production builds, resulting in a doubled /assets/assets/ path
  • Wasm files are now served from public/mediapipe-wasm/ at a stable, unhashed URL

Changes

  • packages/model-driver-mediapipe/tasks/tasks.ts — replace new URL('./assets/wasm', import.meta.url) with `${import.meta.env.BASE_URL}mediapipe-wasm`
  • packages/model-driver-mediapipe/tasks/prepare-tasks.ts — copy wasm files to apps/stage-web/public/mediapipe-wasm/ during postinstall
  • .gitignore — ignore the generated apps/stage-web/public/mediapipe-wasm directory

…oduction 404

Vite production builds only rewrite `new URL('file', import.meta.url)` for
individual file references, not directory references. The previous
`new URL('./assets/wasm', import.meta.url)` resolved to `/assets/assets/wasm`
in production because the bundled chunk lives under `/assets/`, causing a 404
for MediaPipe's vision_wasm_internal.js.

Move wasm files to `apps/stage-web/public/mediapipe-wasm/` (copied during
postinstall) and reference them via `import.meta.env.BASE_URL` so they are
served at a stable, unhashed path in both dev and production.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 29, 2026

⏳ Approval required for deploying to Cloudflare Workers (Preview) for stage-web.

Name Link
🔭 Waiting for approval For maintainers, approve here

Hey, @nekomeowww, @sumimakito, @luoling8192, @LemonNekoGH, kindly take some time to review and approve this deployment when you are available. Thank you! 🙏

@nekomeowww nekomeowww added the pr-review/hold Pull Request that holds to prevent merging label Mar 29, 2026
@nekomeowww
Copy link
Copy Markdown
Member

/hold

alpha 34 release in progress

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the MediaPipe task preparation process to copy WASM assets to a public directory, ensuring they are served from a stable, unhashed path in production. The configuration was also updated to use the application's base URL for these assets. Feedback was provided to ensure the base URL is correctly formatted with a trailing slash to prevent potential path concatenation issues.

Comment on lines +18 to +19
const baseUrl = import.meta.env?.BASE_URL ?? '/'
export const visionTaskWasmRoot = `${baseUrl}mediapipe-wasm`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The BASE_URL environment variable should be validated on startup to ensure it is correctly formatted with a trailing slash, preventing incorrect path concatenation for visionTaskWasmRoot. This aligns with the repository's practice of validating environment variables early to avoid runtime issues.

Suggested change
const baseUrl = import.meta.env?.BASE_URL ?? '/'
export const visionTaskWasmRoot = `${baseUrl}mediapipe-wasm`
const baseUrl = import.meta.env?.BASE_URL ?? '/';
export const visionTaskWasmRoot = (baseUrl.endsWith('/') ? baseUrl : baseUrl + '/') + 'mediapipe-wasm';
References
  1. Validate environment variables on startup to ensure all required variables are present, preventing runtime errors from undefined values.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b1d87e4850

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

// a directory URL to fetch multiple wasm files by name at runtime. We serve them from
// `public/mediapipe-wasm/` so they are available at a stable, unhashed path.
// `import.meta.env` is Vite-only; fall back to '/' for Node.js (e.g. prepare-tasks.ts).
const baseUrl = import.meta.env?.BASE_URL ?? '/'
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Declare Vite env type before reading import.meta.env

packages/model-driver-mediapipe does not include vite/client (or any local ImportMetaEnv declaration) in its TypeScript config, so this new import.meta.env access produces TS2339: Property 'env' does not exist on type 'ImportMeta' during package typecheck. That makes pnpm -F @proj-airi/model-driver-mediapipe typecheck fail for this commit until the env typing is added (or the access is rewritten to avoid import.meta.env).

Useful? React with 👍 / 👎.

@nekomeowww
Copy link
Copy Markdown
Member

/unhold

1 similar comment
@nekomeowww
Copy link
Copy Markdown
Member

/unhold

@nekomeowww
Copy link
Copy Markdown
Member

/hold

@nekomeowww
Copy link
Copy Markdown
Member

/unhold

@nekomeowww
Copy link
Copy Markdown
Member

/hold

@nekomeowww
Copy link
Copy Markdown
Member

/unhold

@github-actions github-actions Bot removed the pr-review/hold Pull Request that holds to prevent merging label Mar 29, 2026
@nekomeowww nekomeowww added bug Something isn't working pr-review/hold Pull Request that holds to prevent merging scope/ui Scope related to UI/UX, or interface improve, perf, and bugs scope/engineering Scope related to toolchain, workflow, workspace, and CI/CD, deploy, packaging, etc. pr-review/hold/unsure Pull Request that unsure about purpose, not sure if needed labels Apr 7, 2026
@nekomeowww nekomeowww requested a review from Lilia-Chen April 7, 2026 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working pr-review/hold/unsure Pull Request that unsure about purpose, not sure if needed pr-review/hold Pull Request that holds to prevent merging scope/engineering Scope related to toolchain, workflow, workspace, and CI/CD, deploy, packaging, etc. scope/ui Scope related to UI/UX, or interface improve, perf, and bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants