Skip to content

fix(nuxt): reach app tsconfig with server auto-import types#437

Merged
HugoRCD merged 2 commits into
mainfrom
fix/nuxt-typecheck-server-globals
Jul 22, 2026
Merged

fix(nuxt): reach app tsconfig with server auto-import types#437
HugoRCD merged 2 commits into
mainfrom
fix/nuxt-typecheck-server-globals

Conversation

@HugoRCD

@HugoRCD HugoRCD commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Closes #435

Problem

Since 2.21.0, nuxt typecheck fails with TS2304: Cannot find name 'useLogger' (and log/createEvlogError) on server routes.

The types/evlog-server.d.ts type template was only registered on the nitro tsconfig context. That reaches .nuxt/tsconfig.server.json, but $fetch's return-type inference does typeof import('../../server/api/...'), which imports the server route modules directly and pulls their auto-imports into the app tsconfig project's typecheck as well — and that project never referenced the template.

Fix

Register the template on both the nitro and nuxt contexts of addTypeTemplate, so the reference also flows into nuxt.d.ts (included by tsconfig.app.json).

Verification

  • Reproduced the bug locally in apps/playground: vue-tsc -p .nuxt/tsconfig.app.json failed with ~18 TS2304 errors before the fix, none after.
  • Added a regression test (packages/evlog/test/nuxt/module-type-templates.test.ts) asserting the type template is registered with { nitro: true, nuxt: true } — verified it fails without the fix and passes with it.
  • pnpm run test, pnpm run lint, pnpm run typecheck all pass across the monorepo (including evlog-playground:typecheck, which exercises this exact scenario).

Summary by CodeRabbit

  • Bug Fixes
    • Fixed Nuxt typecheck failures on server routes caused by missing logging globals (e.g., useLogger / createEvlogError) in inferred route types.
    • Updated Nuxt module typing so server type definitions are available in both the app and server TypeScript contexts, while keeping server-only log scoped to the server project.
  • Tests
    • Added a regression test suite to verify the correct registration of server/app and server-only type templates during Nuxt typecheck.

types/evlog-server.d.ts was only registered on the nitro tsconfig
context, so `useLogger`/`log`/`createEvlogError` resolved to TS2304
in the app tsconfig project. $fetch's return-type inference imports
server route modules directly, pulling their auto-imports into the app
project's typecheck too. Register the template on the nuxt context as
well.

Fixes #435
@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
evlog-docs Ready Ready Preview, Comment, Open in v0 Jul 22, 2026 9:19am
just-use-evlog Ready Ready Preview, Comment Jul 22, 2026 9:19am

Request Review

@github-actions github-actions Bot added the bug Something isn't working label Jul 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions! 🙏

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 0901d9bd-4a6d-4d2c-8080-fb6205ed912c

📥 Commits

Reviewing files that changed from the base of the PR and between 0fd3897 and 1088880.

📒 Files selected for processing (3)
  • .changeset/fix-nuxt-typecheck-server-globals.md
  • packages/evlog/src/nuxt/module.ts
  • packages/evlog/test/nuxt/module-type-templates.test.ts

📝 Walkthrough

Walkthrough

The Nuxt module now registers types/evlog-server.d.ts in both Nitro and Nuxt TypeScript contexts. Regression tests verify declaration registration and log scoping, while a Changesets entry documents the patch release.

Changes

Nuxt typecheck fix

Layer / File(s) Summary
Register server globals across Nuxt TypeScript contexts
packages/evlog/src/nuxt/module.ts, .changeset/fix-nuxt-typecheck-server-globals.md
The server declaration template is registered with both nitro: true and nuxt: true; server-only log remains Nitro-scoped, and the patch changeset documents the fix.
Verify template registration
packages/evlog/test/nuxt/module-type-templates.test.ts
Vitest tests verify registration contexts, useLogger and createEvlogError declarations, and separate server/client log declarations.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • HugoRCD/evlog#412: Adjusts Nuxt auto-import type resolution for server helpers using typeFrom, addressing the same server-helper typing area.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, conventional, and accurately summarizes the Nuxt tsconfig/type-template fix.
Description check ✅ Passed The description covers the problem, fix, and verification, and links the issue, though the checklist is not filled out.
Linked Issues check ✅ Passed The changes satisfy #435 by registering evlog-server.d.ts for both nitro and nuxt and keeping log server-only.
Out of Scope Changes check ✅ Passed The PR only adds the fix, regression test, and release note entry, with no unrelated code changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/nuxt-typecheck-server-globals

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Jul 22, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/evlog@437
npm i https://pkg.pr.new/@evlog/nuxthub@437
npm i https://pkg.pr.new/@evlog/telemetry@437

commit: 1088880

@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/evlog/src/nuxt/module.ts`:
- Around line 494-499: Update the Nuxt type reference configuration in the
visible module setup to keep types/evlog-server.d.ts Nitro-only by removing its
nuxt: true inclusion, while preserving the existing nitro: true registration.
Ensure the app project continues to receive only types/evlog-client.d.ts so
global log and createEvlogError declarations are not duplicated.
🪄 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: e2d6f157-111c-4923-a3d6-3e07099a3d18

📥 Commits

Reviewing files that changed from the base of the PR and between 30ccb08 and 0fd3897.

📒 Files selected for processing (3)
  • .changeset/fix-nuxt-typecheck-server-globals.md
  • packages/evlog/src/nuxt/module.ts
  • packages/evlog/test/nuxt/module-type-templates.test.ts

Comment thread packages/evlog/src/nuxt/module.ts
Address CodeRabbit feedback on #437: declaring the server template's
`log` global on the nuxt context too collided with the client `log`
already declared in evlog-client.d.ts. Nuxt's generated tsconfigs set
skipLibCheck: true, so TypeScript silently kept whichever declaration
it saw first instead of erroring.

Split the server type template: useLogger/createEvlogError stay on
both nitro+nuxt contexts (identical types, no collision), while log
moves to its own nitro-only template.
@HugoRCD
HugoRCD merged commit 18e8910 into main Jul 22, 2026
16 of 17 checks passed
@HugoRCD
HugoRCD deleted the fix/nuxt-typecheck-server-globals branch July 22, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Nuxt: nuxt typecheck fails with TS2304 on server auto-imports since 2.21.0 (evlog-server.d.ts template never reaches the generated tsconfigs)

1 participant