Skip to content

App context type-checking server files causes it to fail when importing from #imports #33979

Closed

Description

@cernymatej

Reproduction

https://stackblitz.com/edit/nuxt-starter-vg7snjkv?file=server%2Fapi%2Findex.get.ts

created by @amandesai01

Describe the bug

Similar to #33627, running typecheck fails when users import server-only code from #imports in server files because the app context, where the server-only code isn't available, ends up checking the files too.

For utils from h3, for example, it is fine to import them directly from the package. However, utils from modules, which are added via addServerImports or addServerImportsDir, this can be a serious issue.
This is often the only way to import such functions, like it is the case in nuxt-auth-utils, for example.

We should probably add something like an #imports/server alias, as Daniel suggested.

Additional context

No response

Logs

Activity

  1. bolt-new-by-stackblitz commented on Dec 28, 2025

    @bolt-new-by-stackblitz
  2. added theissue type on Dec 28, 2025
  3. coderabbitai commented on Dec 28, 2025

    @coderabbitai
    Contributor

    📝 CodeRabbit Plan Mode

    Generate an implementation plan and prompts that you can use with your favorite coding agent.

    • Create Plan
    Examples

    🔗 Similar Issues

    Possible Duplicates

    🔗 Related PRs

    #28682 - feat(schema,nuxt): add shared folder to alias and auto-imports [merged]
    #32594 - fix(nuxt): include shared types in tsconfig.server.json [merged]
    #33308 - fix(vite): duplicate server style imports [merged]
    #33870 - feat(schema): add #server alias for server directory imports [merged]
    #33927 - fix(webpack,rspack): resolve deep imports in virtual files [merged]

    👤 Suggested Assignees

    🧪 Issue enrichment is currently in open beta.

    You can configure auto-planning by selecting labels in the issue_enrichment configuration.

    To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord!

  4. added
    nitro
    🔨 p3-minor
    and removed on Dec 28, 2025
  5. cernymatej commented on Dec 28, 2025

    @cernymatej
    MemberAuthor

    as @amandesai01 pointed out, this is a problem not only for server endpoints but also for other files in the server part

  6. changed the title [-]App context type-checking server endpoints causes it to fail when importing from `#imports`[/-] [+]App context type-checking server files causes it to fail when importing from `#imports`[/+] on Dec 28, 2025
  7. chairulakmal commented on Aug 4, 2026

    @chairulakmal
    Contributor

    Hi @cernymatej

    Is this still open? There's no open PR here, so I'd like to pick it up. I did #35697.

    I've read the code and would go with your #imports/server: point it at the nitro-imports.d.ts Nitro already writes instead of generating a second copy, and register it on the Nitro side only, so importing it from a component still fails rather than bundling server code into the client. @danielroe suggested #imports/nuxt + #imports/nitro in nuxt/cli#1143 though, so let me know if you'd rather have the pair.

    One thing I found while reproducing: .nuxt/tsconfig.json rebuilds its exclude from scratch and drops the server dir Nitro adds to tsconfig.app.json, so the legacy single config type-checks server files directly. Should I fix it in this PR too, or keep it separate?

    After #35938 the server imports run regardless of experimental.nitroAutoImports, so this hits default v5 apps too.

    I'll open a PR once you confirm the naming.

  8. chairulakmal commented on Aug 11, 2026

    @chairulakmal
    Contributor

    Opened #36039

    I went with #imports/server. Importing it from a component still fails the build rather than bundling server code into the client. I can modify it into #imports/nuxt + #imports/nitro pair if needed.

  9. danielroe commented on Sep 6, 2026

    @danielroe
    Member

    this has been resolved in #36265 and will be present in nuxt v5; server files will import from #imports/server instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    nitrotypes🔨 p3-minor

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions