Repository navigation
fix(kit): surface module load errors instead of masking as missing - #35497
Conversation
loadNuxtModuleInstance resolved and imported a module in one try/catch, so any error other than the known "not found" codes fell through to a generic "Could not load `x`. Is it installed?" with no cause. An installed module that threw while loading was reported as not installed. Split resolution from evaluation: resolveModuleURL failures keep the "is it installed?" wording (now with the original cause), while errors thrown during jiti.import are surfaced as "Error while importing module".
|
We've flagged this as a potential contribution without a human behind it. We welcome the thoughtful use of AI tools when contributing to Nuxt, but ask all contributors to follow two core principles:
Please review our AI-assisted contribution guidelines and update this contribution if needed. We're closing this for now as the account looks automated. If we got that wrong, please just reopen the PR and we'll take another look. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/kit/test/module.test.ts (1)
509-526: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert the preserved cause contract without re-importing.
The new tests check the surfaced message, but not that the original error is attached as
cause. Capturing each rejection once would also avoid re-running side-effecting module evaluation for the negative assertion.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/kit/test/module.test.ts` around lines 509 - 526, Update the module-loading tests in module.test.ts so each rejection is awaited only once and the resulting error object is inspected directly rather than re-calling loadNuxtModuleInstance for the negative assertion. In the relevant cases around loadNuxtModuleInstance and the throwing-module/broken-dep-module/subpath-module scenarios, assert that the rejected error preserves the original failure as cause while still checking the surfaced message, and keep the missing-module case asserting the installed-module hint.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/kit/test/module.test.ts`:
- Around line 474-501: Clear the deterministic temp fixture directory before
setting up the module fixtures in beforeAll so stale files from previous runs
cannot affect the missing-module cases. Update the setup around tempDir and
loadNuxt in module.test.ts to remove the existing directory first, then recreate
throwingModule, brokenDepModule, depWithExports, and subpathModule from scratch
before calling loadNuxt.
---
Nitpick comments:
In `@packages/kit/test/module.test.ts`:
- Around line 509-526: Update the module-loading tests in module.test.ts so each
rejection is awaited only once and the resulting error object is inspected
directly rather than re-calling loadNuxtModuleInstance for the negative
assertion. In the relevant cases around loadNuxtModuleInstance and the
throwing-module/broken-dep-module/subpath-module scenarios, assert that the
rejected error preserves the original failure as cause while still checking the
surfaced message, and keep the missing-module case asserting the
installed-module hint.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: deabdbfd-dcd1-454a-a067-8408d9e31f89
📒 Files selected for processing (2)
packages/kit/src/module/install.tspackages/kit/test/module.test.ts
|
I opened this before I saw #35387, so this PR becomes more of a correctness scope but the main work was done there. |
Clear the temp fixture dir before setup so stale files can't affect the missing-module case, and inspect each rejection once, asserting the original error is preserved as cause.
@nuxt/kit
@nuxt/nitro-server
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
Merging this PR will not alter performance
Comparing Footnotes
|
|
linking #35660 |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/kit/src/module/install.ts (1)
395-397: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winThe error diagnostic is neither thrown nor logged.
It appears that the error object created by
kitDiagnostics.NUXT_B8019is instantiated but not used. Since other methods onkitDiagnosticsin this file return error instances that must be explicitly thrown (e.g.throw kitDiagnostics.NUXT_B8017(...)), calling it here without athrowor logging statement effectively swallows the lifecycle hook error, hiding potential issues during module installation or upgrades.Consider either throwing the error or logging it appropriately.
🐛 Proposed fix (if throwing is the intended behaviour)
} catch (e) { - kitDiagnostics.NUXT_B8019({ phase: !previousVersion ? 'install' : 'upgrade', name: meta.name, error: String(e) }) + throw kitDiagnostics.NUXT_B8019({ phase: !previousVersion ? 'install' : 'upgrade', name: meta.name, error: String(e) }) }🐛 Proposed fix (if logging is the intended behaviour)
} catch (e) { - kitDiagnostics.NUXT_B8019({ phase: !previousVersion ? 'install' : 'upgrade', name: meta.name, error: String(e) }) + console.warn(kitDiagnostics.NUXT_B8019({ phase: !previousVersion ? 'install' : 'upgrade', name: meta.name, error: String(e) })) }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/kit/src/module/install.ts` around lines 395 - 397, Update the catch block in the module installation lifecycle flow to use the error returned by kitDiagnostics.NUXT_B8019 instead of discarding it. Follow the surrounding kitDiagnostics convention by explicitly throwing the returned diagnostic, unless this flow’s established behavior requires logging it through the appropriate logger.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@packages/kit/src/module/install.ts`:
- Around line 395-397: Update the catch block in the module installation
lifecycle flow to use the error returned by kitDiagnostics.NUXT_B8019 instead of
discarding it. Follow the surrounding kitDiagnostics convention by explicitly
throwing the returned diagnostic, unless this flow’s established behavior
requires logging it through the appropriate logger.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: a837ddda-2620-46a2-98d5-9ef39212a4c4
📒 Files selected for processing (2)
packages/kit/src/module/install.tspackages/kit/test/module.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/kit/test/module.test.ts
…35497) Co-authored-by: Daniel Roe <[email protected]> (cherry picked from commit 31224d7)
…35497) Co-authored-by: Daniel Roe <[email protected]> (cherry picked from commit 31224d7)
🔗 Linked issue
Resolves harlan-zw/nuxt-seo#537
resolves #35660
📚 Description
Following on from #35387: that attached the original error as the cause, but a module that resolves and then throws while loading still reports as not installed, so the message points at the wrong problem.
A genuinely missing module keeps the "is it installed?" message. A module that is found but fails to load now surfaces the actual error it threw.