Repository navigation
fix(webpack,rspack): resolve deep imports in virtual files - #33927
Conversation
|
|
WalkthroughThis PR expands server externals resolution and Vite plugin wiring. It adds path/URL utilities, a VIRTUAL_RE for virtual-module detection, and a resolver Possibly related PRs
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Repository UI Review profile: CHILL Plan: Pro ⛔ Files ignored due to path filters (3)
📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (2)**/*.{ts,tsx,vue}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
**/*.{ts,tsx,js,jsx,vue}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
🧠 Learnings (3)📓 Common learnings📚 Learning: 2024-11-05T15:22:54.759ZApplied to files:
📚 Learning: 2024-12-12T12:36:34.871ZApplied to files:
🧬 Code graph analysis (1)packages/nuxt/src/core/nuxt.ts (2)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (3)
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 |
@nuxt/kit
@nuxt/nitro-server
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
CodSpeed Performance ReportMerging #33927 will not alter performanceComparing Summary
Footnotes |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
packages/webpack/src/configs/server.ts (2)
13-13: Consider extractingVIRTUAL_REto a shared utility.This pattern is duplicated in
packages/vite/src/plugins/resolve-deep-imports.ts. Extracting it to@nuxt/kitor a shared constants module would improve maintainability.
119-137: Core fix for virtual file resolution looks correct.The logic properly attempts local resolution before externalising, which is essential for deep imports in virtual files.
However, the empty catch block silently swallows all errors. Consider logging at debug level to aid troubleshooting, consistent with the Vite plugin's
logger.debug('Could not resolve id', ...)pattern.🔎 Suggested improvement for debugging
} catch { - // Ignore resolution errors, fall through to externalize + // Ignore resolution errors, fall through to externalize + logger.debug('Could not resolve', request, 'from', context) }
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
packages/nuxt/package.jsonis excluded by!**/package.json
📒 Files selected for processing (7)
eslint.config.mjs(1 hunks)packages/nuxt/src/core/nuxt.ts(0 hunks)packages/vite/src/plugins/resolve-deep-imports.ts(2 hunks)packages/vite/src/plugins/resolved-externals.ts(1 hunks)packages/vite/src/vite.ts(2 hunks)packages/webpack/src/configs/server.ts(5 hunks)tsconfig.json(1 hunks)
💤 Files with no reviewable changes (1)
- packages/nuxt/src/core/nuxt.ts
✅ Files skipped from review due to trivial changes (1)
- tsconfig.json
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,vue}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Follow standard TypeScript conventions and best practices
Files:
packages/vite/src/plugins/resolve-deep-imports.tspackages/vite/src/vite.tspackages/webpack/src/configs/server.tspackages/vite/src/plugins/resolved-externals.ts
**/*.{ts,tsx,js,jsx,vue}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.{ts,tsx,js,jsx,vue}: Use clear, descriptive variable and function names
Add comments only to explain complex logic or non-obvious implementations
Keep functions focused and manageable (generally under 50 lines), and extract complex logic into separate domain-specific files
Remove code that is not used or needed
Use error handling patterns consistently
Files:
packages/vite/src/plugins/resolve-deep-imports.tspackages/vite/src/vite.tspackages/webpack/src/configs/server.tspackages/vite/src/plugins/resolved-externals.ts
🧠 Learnings (2)
📚 Learning: 2024-11-05T15:22:54.759Z
Learnt from: GalacticHypernova
Repo: nuxt/nuxt PR: 26468
File: packages/nuxt/src/components/plugins/loader.ts:24-24
Timestamp: 2024-11-05T15:22:54.759Z
Learning: In `packages/nuxt/src/components/plugins/loader.ts`, the references to `resolve` and `distDir` are legacy code from before Nuxt used the new unplugin VFS and will be removed.
Applied to files:
packages/vite/src/plugins/resolve-deep-imports.tspackages/vite/src/vite.tspackages/webpack/src/configs/server.tspackages/vite/src/plugins/resolved-externals.tseslint.config.mjs
📚 Learning: 2024-12-12T12:36:34.871Z
Learnt from: huang-julien
Repo: nuxt/nuxt PR: 29366
File: packages/nuxt/src/app/components/nuxt-root.vue:16-19
Timestamp: 2024-12-12T12:36:34.871Z
Learning: In `packages/nuxt/src/app/components/nuxt-root.vue`, when optimizing bundle size by conditionally importing components based on route metadata, prefer using inline conditional imports like:
```js
const IsolatedPage = route?.meta?.isolate ? defineAsyncComponent(() => import('#build/isolated-page.mjs')) : null
```
instead of wrapping the import in a computed property or importing the component unconditionally.
Applied to files:
packages/vite/src/plugins/resolve-deep-imports.tspackages/vite/src/vite.tspackages/webpack/src/configs/server.tspackages/vite/src/plugins/resolved-externals.tseslint.config.mjs
🧬 Code graph analysis (2)
packages/vite/src/vite.ts (2)
packages/vite/src/plugins/resolve-deep-imports.ts (1)
ResolveDeepImportsPlugin(11-88)packages/vite/src/plugins/resolved-externals.ts (1)
ResolveExternalsPlugin(8-66)
packages/webpack/src/configs/server.ts (3)
packages/webpack/src/utils/config.ts (1)
WebpackConfigContext(6-17)packages/kit/src/index.ts (3)
tryImportModule(45-45)directoryToURL(45-45)resolveAlias(37-37)packages/kit/src/resolve.ts (1)
resolveAlias(92-95)
🔇 Additional comments (10)
packages/vite/src/plugins/resolve-deep-imports.ts (2)
5-5: LGTM!Consolidating imports from
@nuxt/kitis cleaner and ensures consistent utility usage across the codebase.
63-63: Fallback toappDiris appropriate for Nuxt template resolution.Using
nuxt.options.appDiras the fallback directory aligns with how Nuxt templates are resolved, as they are typically relative to the application context rather than the package directory.packages/vite/src/vite.ts (2)
41-42: LGTM!Import additions for the new deep imports and externals resolution plugins.
193-195: Plugin registration order is correct.
ResolveDeepImportsPluginusesenforce: 'post'andResolveExternalsPluginusesenforce: 'pre', ensuring externals are marked before other resolution attempts, whilst deep imports are resolved as a final fallback. The descriptive comment clarifies the purpose.packages/webpack/src/configs/server.ts (4)
1-5: LGTM!Imports are appropriately grouped and provide necessary utilities for the enhanced resolution logic.
44-44: LGTM!The async conversion and dynamic import pattern for Nitro runtime meta aligns with the Vite implementation in
resolved-externals.ts, ensuring consistent runtime dependency handling across build tools.Also applies to: 60-62
85-90: LGTM!The conditions array correctly prioritises
nodefor server builds and includes bothimportandrequirefor CommonJS interoperability.
96-107: LGTM!The resolution attempt for known externals enables Nitro to handle version resolution correctly. Returning the absolute path when available, with a fallback to simple externalisation, is a sound approach.
packages/vite/src/plugins/resolved-externals.ts (1)
6-6: Import path change tonuxt/metarequires verification of module export availability.The switch from a relative path to
nuxt/metacannot be confirmed as a valid public export. TheruntimeDependenciesexport is found imported from './packages/nuxt/src/meta.mjs' in the Nuxt repository, but no evidence exists thatnuxt/metais a public API. Verify that this module export is available in Nuxt 4 before merging this change.eslint.config.mjs (1)
10-10: No action required. The import has been verified to resolve correctly. Thenuxt/metaexport is properly configured in the package.json as"./meta": "./meta.mjs", and the meta.mjs file exists with the correct exports. The import in eslint.config.mjs will resolve without issues during linting.
🔗 Linked issue
extracted from #33005
📚 Description
previously we were relying on nitro resolving these files, which happened to work but nitro is making its module resolution algorithm more performant in v3
👉 Next steps