Skip to content

fix(kit,nuxt): pass error as cause when we re-throw - #35387

Merged
danielroe merged 1 commit into
mainfrom
fix/lint-errors
Jun 18, 2026
Merged

danielroe merged 1 commit into
mainfrom
fix/lint-errors

Conversation

@danielroe

Copy link
Copy Markdown
Member

🔗 Linked issue

📚 Description

flagged up in #35369 in eslint config improvements

@danielroe
danielroe requested a review from huang-julien June 18, 2026 12:33
@github-actions github-actions Bot added 5.x 🐛 bug Something isn't working as expected labels Jun 18, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jun 18, 2026

Copy link
Copy Markdown

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@35387

@nuxt/nitro-server

npm i https://pkg.pr.new/@nuxt/nitro-server@35387

nuxt

npm i https://pkg.pr.new/nuxt@35387

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@35387

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@35387

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@35387

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@35387

commit: 989081e

@coderabbitai

This comment has been minimized.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 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/src/module/install.ts`:
- Around line 346-352: In the module installation error handling block starting
at line 346, when the code matches MODULE_NOT_FOUND or ERR_MODULE_NOT_FOUND, the
nested condition on line 350 only throws if the module is found and doesn't
match nuxtModule. However, if this condition is false (module is undefined or
module includes nuxtModule), execution falls through without throwing, losing
the original error context. Add a fallthrough throw statement after the
conditional block that throws an error with the cause property set to the
original error to ensure the error context is preserved in all MODULE_NOT_FOUND
paths.
🪄 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: 3a1bfb28-ab90-4c1f-a836-2c7472d53d25

📥 Commits

Reviewing files that changed from the base of the PR and between 886e12f and 989081e.

📒 Files selected for processing (3)
  • packages/kit/src/module/define.ts
  • packages/kit/src/module/install.ts
  • packages/nuxt/src/app/components/nuxt-island.ts

Comment on lines 346 to 352
if (code === 'MODULE_NOT_FOUND' || code === 'ERR_MODULE_NOT_FOUND') {
const module = MissingModuleMatcher.exec((error as Error).message)?.[1]
// verify that it's missing the nuxt module otherwise it may be a sub dependency of the module itself
// i.e. module is importing a module that is missing
if (module && !module.includes(nuxtModule as string)) {
throw new TypeError(`Error while importing module \`${nuxtModule}\`: ${error}`)
throw new TypeError(`Error while importing module \`${nuxtModule}\`: ${error}`, { cause: error })
}

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Preserve cause in the MODULE_NOT_FOUND fallthrough path.

When Line 346 matches and the Line 350 condition is false, execution falls through to the generic throw without cause, so the original import error context is still lost.

Suggested patch
   } catch (error: unknown) {
     const code = (error as Error & { code?: string }).code
     if (code === 'ERR_PACKAGE_PATH_NOT_EXPORTED' || code === 'ERR_UNSUPPORTED_DIR_IMPORT' || code === 'ENOTDIR') {
       throw new TypeError(`Could not load \`${nuxtModule}\`. Is it installed?`, { cause: error })
     }
     if (code === 'MODULE_NOT_FOUND' || code === 'ERR_MODULE_NOT_FOUND') {
       const module = MissingModuleMatcher.exec((error as Error).message)?.[1]
       // verify that it's missing the nuxt module otherwise it may be a sub dependency of the module itself
       // i.e. module is importing a module that is missing
       if (module && !module.includes(nuxtModule as string)) {
         throw new TypeError(`Error while importing module \`${nuxtModule}\`: ${error}`, { cause: error })
       }
     }
+    throw new TypeError(`Could not load \`${nuxtModule}\`. Is it installed?`, { cause: error })
   }
-
-  throw new TypeError(`Could not load \`${nuxtModule}\`. Is it installed?`)
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (code === 'MODULE_NOT_FOUND' || code === 'ERR_MODULE_NOT_FOUND') {
const module = MissingModuleMatcher.exec((error as Error).message)?.[1]
// verify that it's missing the nuxt module otherwise it may be a sub dependency of the module itself
// i.e. module is importing a module that is missing
if (module && !module.includes(nuxtModule as string)) {
throw new TypeError(`Error while importing module \`${nuxtModule}\`: ${error}`)
throw new TypeError(`Error while importing module \`${nuxtModule}\`: ${error}`, { cause: error })
}
} catch (error: unknown) {
const code = (error as Error & { code?: string }).code
if (code === 'ERR_PACKAGE_PATH_NOT_EXPORTED' || code === 'ERR_UNSUPPORTED_DIR_IMPORT' || code === 'ENOTDIR') {
throw new TypeError(`Could not load \`${nuxtModule}\`. Is it installed?`, { cause: error })
}
if (code === 'MODULE_NOT_FOUND' || code === 'ERR_MODULE_NOT_FOUND') {
const module = MissingModuleMatcher.exec((error as Error).message)?.[1]
// verify that it's missing the nuxt module otherwise it may be a sub dependency of the module itself
// i.e. module is importing a module that is missing
if (module && !module.includes(nuxtModule as string)) {
throw new TypeError(`Error while importing module \`${nuxtModule}\`: ${error}`, { cause: error })
}
}
throw new TypeError(`Could not load \`${nuxtModule}\`. Is it installed?`, { cause: error })
}
🧰 Tools
🪛 OpenGrep (1.22.0)

[ERROR] 347-347: Dynamic command passed to child_process.exec/execSync. Use child_process.execFile or spawn with an argument array instead.

(coderabbit.command-injection.exec-js)

🤖 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 346 - 352, In the module
installation error handling block starting at line 346, when the code matches
MODULE_NOT_FOUND or ERR_MODULE_NOT_FOUND, the nested condition on line 350 only
throws if the module is found and doesn't match nuxtModule. However, if this
condition is false (module is undefined or module includes nuxtModule),
execution falls through without throwing, losing the original error context. Add
a fallthrough throw statement after the conditional block that throws an error
with the cause property set to the original error to ensure the error context is
preserved in all MODULE_NOT_FOUND paths.

@codspeed

codspeed Bot commented Jun 18, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 23.78%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 1 regressed benchmark
✅ 20 untouched benchmarks
⏩ 3 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ loadNuxtConfig in the basic test fixture (types) 16.8 ms 22.1 ms -23.78%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing fix/lint-errors (989081e) with main (886e12f)

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@danielroe
danielroe merged commit 549949f into main Jun 18, 2026
33 checks passed
@danielroe
danielroe deleted the fix/lint-errors branch June 18, 2026 13:14
@github-actions github-actions Bot mentioned this pull request Jun 18, 2026
2 of 5 tasks
danielroe added a commit that referenced this pull request Jun 23, 2026
@github-actions github-actions Bot mentioned this pull request Jun 23, 2026
@github-actions github-actions Bot mentioned this pull request Jun 23, 2026
@github-actions github-actions Bot mentioned this pull request Jul 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5.x 🐛 bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant