fix(model-driver-mediapipe): serve wasm assets from public/ to fix production 404#1509
fix(model-driver-mediapipe): serve wasm assets from public/ to fix production 404#1509lietblue wants to merge 2 commits intomoeru-ai:mainfrom
Conversation
…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.
⏳ Approval required for deploying to Cloudflare Workers (Preview) for stage-web.
Hey, @nekomeowww, @sumimakito, @luoling8192, @LemonNekoGH, kindly take some time to review and approve this deployment when you are available. Thank you! 🙏 |
|
/hold alpha 34 release in progress |
There was a problem hiding this comment.
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.
| const baseUrl = import.meta.env?.BASE_URL ?? '/' | ||
| export const visionTaskWasmRoot = `${baseUrl}mediapipe-wasm` |
There was a problem hiding this comment.
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.
| 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
- Validate environment variables on startup to ensure all required variables are present, preventing runtime errors from undefined values.
There was a problem hiding this comment.
💡 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 ?? '/' |
There was a problem hiding this comment.
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 👍 / 👎.
|
/unhold |
1 similar comment
|
/unhold |
|
/hold |
|
/unhold |
|
/hold |
|
/unhold |
Summary
GET /assets/assets/wasm/vision_wasm_internal.js 404error when runningvite build && vite previewfor stage-webnew URL('./assets/wasm', import.meta.url)is a directory reference that Vite does not rewrite in production builds, resulting in a doubled/assets/assets/pathpublic/mediapipe-wasm/at a stable, unhashed URLChanges
packages/model-driver-mediapipe/tasks/tasks.ts— replacenew 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 toapps/stage-web/public/mediapipe-wasm/duringpostinstall.gitignore— ignore the generatedapps/stage-web/public/mediapipe-wasmdirectory