[FIX] Handle missing plugin asset imports in Vite build#1818
[FIX] Handle missing plugin asset imports in Vite build#1818hari-kuriakose merged 3 commits intomainfrom
Conversation
The optionalPluginImports Vite plugin resolved all missing plugin files to a module that only throws, which breaks static imports (no default export). Asset imports (SVG, PNG, etc.) now resolve to a module that exports an empty string, so static `import logo from "..."` statements don't crash the build when assets are absent. JS/TS plugin imports still throw so the existing try/catch dynamic import pattern continues to work. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Organization UI Review profile: CHILL Plan: Pro Cache: Disabled due to Reviews > Disable Cache setting Knowledge base: Disabled due to 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Summary by CodeRabbit
WalkthroughAdds asset-import handling to the Vite config: normalizes import paths, recognizes asset extensions, returns a sentinel Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@frontend/vite.config.js`:
- Around line 57-60: The resolveId and load hooks are using
path.extname(resolved) directly so imports with queries/hashes like
"./logo.svg?react" yield ".svg?react" and miss ASSET_EXTENSIONS; update
resolveId (the code using path.extname and ASSET_EXTENSIONS) to strip query
string and hash from resolved before calling path.extname (e.g. remove anything
from the first "?" or "#" onward), and make the same change in the load hook
where EMPTY_ASSET_MODULE_ID vs EMPTY_MODULE_ID is decided so that assets with
query params/hashes are correctly detected and return EMPTY_ASSET_MODULE_ID.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to Reviews > Disable Cache setting
Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting
📒 Files selected for processing (1)
frontend/vite.config.js
path.extname() on query-suffixed imports like "./logo.svg?react" returns ".svg?react" instead of ".svg", causing the ASSET_EXTENSIONS check to fail and routing asset imports to the throwing module instead of the empty-string default export. Strip query strings and hashes before resolving the path. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Frontend Lint Report (Biome)✅ All checks passed! No linting or formatting issues found. |
|



What
optionalPluginImportsplugin to handle missing asset imports (SVG, PNG, JPEG, etc.) gracefully by exporting a default empty string instead of throwingWhy
ProductContentComponents.jsx(a cloud plugin) uses static imports for asset files fromplugins/assets/llmWhisperer/plugins/assets/llmWhisperer/, so these assets are missingtry/catchimports but breaks static imports because Rollup requires adefaultexport"default" is not exported by "optional-plugin-empty"How
EMPTY_ASSET_MODULE_ID) for asset file imports.svg,.png,.jpg,.jpeg,.gif,.webp,.ico,.bmp,.tiff), resolve it to a module that doesexport default ''try { await import(...) } catch {}pattern still worksCan this PR break any existing features. If yes, please list possible items. If no, please explain why. (PS: Admins do not merge the PR without this section filled)
nullfor those and Vite processes them normally. Missing JS/TS plugin imports still throw as before.Database Migrations
Env Config
Relevant Docs
Related Issues or PRs
ProductContentComponents.jsxDependencies Versions
Notes on Testing
Screenshots
Checklist
I have read and understood the Contribution Guidelines.