Skip to content

vue-tsc overwrite server imports with app imports #29263

Closed

Description

@Barbapapazes

Environment


  • Operating System: Darwin
  • Node Version: v20.17.0
  • Nuxt Version: 3.13.2
  • CLI Version: 3.14.0
  • Nitro Version: 2.9.7
  • Package Manager: [email protected]
  • Builder: -
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

Barbapapazes/nuxt-authorization#12

Or

Clone the module https://github.com/Barbapapazes/nuxt-authorization, install deps, cd to the playground and run npm run typecheck

Describe the bug

This module provides utilities with the same name on both the app and the server.

This means that it's possible to import authorize from #imports in both the app and the server but this function does not have the same type definition (the server one use event. When running vue-tsc, it raises an error because it resolves server imports using app imports.

`vue-tsc` error

nuxt-authorization/playground on  main [✘!?] via ⬢ v20.17.0 
➜ nr typecheck 

> nuxt-authorization-playground@ typecheck /Users/esoub/dev/p/nuxt-authorization/playground
> nuxi typecheck

ℹ Running with compatibility version 4                                                               3:02:34 PM
server/api/products/[id].patch.ts:11:19 - error TS2345: Argument of type 'H3Event<EventHandlerRequest>' is not assignable to parameter of type 'BouncerAbility<any>'.
  Type 'H3Event<EventHandlerRequest>' is missing the following properties from type 'BouncerAbility<any>': original, execute, allowGuest

11   await authorize(event, editProduct, product)
                     ~~~~~

server/api/products/index.get.ts:4:19 - error TS2345: Argument of type 'H3Event<EventHandlerRequest>' is not assignable to parameter of type 'BouncerAbility<any>'.

4   await authorize(event, listProducts)
                    ~~~~~

server/api/products/index.post.ts:4:19 - error TS2345: Argument of type 'H3Event<EventHandlerRequest>' is not assignable to parameter of type 'BouncerAbility<any>'.

4   await authorize(event, createProduct)
                    ~~~~~


Found 3 errors in 3 files.

Errors  Files
     1  server/api/products/[id].patch.ts:11
     1  server/api/products/index.get.ts:4
     1  server/api/products/index.post.ts:4

[3:02:35 PM]  ERROR  Command failed with exit code 2: '/Users/esoub/dev/p/nuxt-authorization/node_modules/.pnpm/[email protected][email protected]/node_modules/vue-tsc/bin/vue-tsc.js' --noEmit

  at getFinalError (/Users/esoub/dev/p/nuxt-authorization/node_modules/.pnpm/[email protected]/node_modules/nuxi/dist/chunks/index3.mjs:1124:9)
  at makeError (/Users/esoub/dev/p/nuxt-authorization/node_modules/.pnpm/[email protected]/node_modules/nuxi/dist/chunks/index3.mjs:3604:16)
  at getAsyncResult (/Users/esoub/dev/p/nuxt-authorization/node_modules/.pnpm/[email protected]/node_modules/nuxi/dist/chunks/index3.mjs:7831:4)
  at handlePromise (/Users/esoub/dev/p/nuxt-authorization/node_modules/.pnpm/[email protected]/node_modules/nuxi/dist/chunks/index3.mjs:7814:17)
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  at async Object.run (/Users/esoub/dev/p/nuxt-authorization/node_modules/.pnpm/[email protected]/node_modules/nuxi/dist/chunks/typecheck.mjs:81:7)
  at async runCommand$1 (/Users/esoub/dev/p/nuxt-authorization/node_modules/.pnpm/[email protected]/node_modules/nuxi/dist/shared/nuxi.3e201632.mjs:1648:16)
  at async runCommand$1 (/Users/esoub/dev/p/nuxt-authorization/node_modules/.pnpm/[email protected]/node_modules/nuxi/dist/shared/nuxi.3e201632.mjs:1639:11)
  at async runMain$1 (/Users/esoub/dev/p/nuxt-authorization/node_modules/.pnpm/[email protected]/node_modules/nuxi/dist/shared/nuxi.3e201632.mjs:1777:7) 



[3:02:35 PM]  ERROR  Command failed with exit code 2: '/Users/esoub/dev/p/nuxt-authorization/node_modules/.pnpm/[email protected][email protected]/node_modules/vue-tsc/bin/vue-tsc.js' --noEmit

Additional context

No response

Logs

No response

Activity

  1. github-actions commented on Oct 3, 2024

    @github-actions
    Contributor

    Stackblitz link for the reproduction: Stackblitz

  2. danielroe commented on Oct 6, 2024

    @danielroe
    Member

    Probably we need to update typecheck to run vue-tsc twice - one with root tsconfig and another with tsconfig in server dir. Does it work if you do that manually?

  3. added
    🐛 bug
    🔨 p3-minor
    and removed on Oct 6, 2024
  4. Barbapapazes commented on Oct 6, 2024

    @Barbapapazes
    ContributorAuthor
    1. I have to update tsconfig.server.json with skipLibCheck: true but then I partially works because it continue to typecheck the app folder
    `vue-tsc` logs

    nuxt-authorization/playground on  main via ⬢ v20.17.0 
    ➜ npx vue-tsc -p server/tsconfig.json       
    app/app.vue:5:17 - error TS2304: Cannot find name 'ref'.
    
    5 const product = ref<Product>({
                      ~~~
    
    app/plugins/authorization-resolver.ts:1:34 - error TS2307: Cannot find module '#app' or its corresponding type declarations.
    
    1 import { defineNuxtPlugin } from '#app'
                                       ~~~~~~
    
    nuxt.config.ts:1:16 - error TS2552: Cannot find name 'defineNuxtConfig'. Did you mean 'defineNitroConfig'?
    
    1 export default defineNuxtConfig({
                     ~~~~~~~~~~~~~~~~
    
      ../node_modules/.pnpm/[email protected][email protected]/node_modules/nitropack/dist/shared/nitro.18796496.d.ts:923:11
        923     const defineNitroConfig: (config: NitroConfig) => NitroConfig;
                      ~~~~~~~~~~~~~~~~~
        'defineNitroConfig' is declared here.
    
    
    Found 3 errors in 3 files.
    
    Errors  Files
         1  app/app.vue:5
         1  app/plugins/authorization-resolver.ts:1
         1  nuxt.config.ts:1

    1. For the app, I still have the same error
    `vue-tsc` logs

    nuxt-authorization/playground on  main via ⬢ v20.17.0 
    ➜ npx vue-tsc -p tsconfig.json       
    server/api/products/[id].patch.ts:11:19 - error TS2345: Argument of type 'H3Event<EventHandlerRequest>' is not assignable to parameter of type 'BouncerAbility<any>'.
      Type 'H3Event<EventHandlerRequest>' is missing the following properties from type 'BouncerAbility<any>': original, execute, allowGuest
    
    11   await authorize(event, editProduct, product)
                         ~~~~~
    
    server/api/products/index.get.ts:4:19 - error TS2345: Argument of type 'H3Event<EventHandlerRequest>' is not assignable to parameter of type 'BouncerAbility<any>'.
      Type 'H3Event<EventHandlerRequest>' is missing the following properties from type 'BouncerAbility<any>': original, execute, allowGuest
    
    4   await authorize(event, listProducts)
                        ~~~~~
    
    server/api/products/index.post.ts:4:19 - error TS2345: Argument of type 'H3Event<EventHandlerRequest>' is not assignable to parameter of type 'BouncerAbility<any>'.
      Type 'H3Event<EventHandlerRequest>' is missing the following properties from type 'BouncerAbility<any>': original, execute, allowGuest
    
    4   await authorize(event, createProduct)
                        ~~~~~
    
    
    Found 3 errors in 3 files.
    
    Errors  Files
         1  server/api/products/[id].patch.ts:11
         1  server/api/products/index.get.ts:4
         1  server/api/products/index.post.ts:4

  5. Barbapapazes commented on Oct 6, 2024

    @Barbapapazes
    ContributorAuthor

    In the tsconfig.server.json, the line 115 (see screenshot above) that cause an issue. After removing it, no more error

    Image

  6. BobbieGoede commented on Jan 19, 2025

    @BobbieGoede
    Member

    FYI - I don't think we can remove the ../**/* include entry in tsconfig.server.json without changes to nitro, see https://github.com/nitrojs/nitro/blob/v2/src/core/build/types.ts#L274

  7. removed
    🐛 bug
    on Apr 29, 2025
  8. danielroe commented on Jun 26, 2025

    @danielroe
    Member

    This is something I would love to resolve although it is very tricky as the 'nuxt/app' context also needs to include some nitro files in order for api return type inference to work.

    For now, I recommend server/client utilities to be isomorphic - that is, have the same signature. For example, as we do with useRuntimeConfig in Nuxt, or useSanity in @nuxtjs/sanity

    Having said that, with the merge of #30665 (for v4) we are much closer and we support a single typechecking step.

  9. chairulakmal commented on Aug 12, 2026

    @chairulakmal
    Contributor

    Hi @Barbapapazes

    #36039 might help here. It adds an #imports/server alias that resolves to Nitro's auto-imports in both the app and the server context, so in a server file you can import the server utility explicitly:

    // server/api/foo.ts
    import { authorize } from '#imports/server'

    Your two authorize keep their own signature, so you don't have to make them the same.

    It does not fix plain #imports in a server file. The app context still resolves that to the app auto-imports, and one alias cannot resolve to two different sets in two contexts that both include the file. So it works around the name collision without fixing the cause.

    If you still hit this in nuxt-authorization, the playground would be a good place to try this.

  10. danielroe commented on Sep 6, 2026

    @danielroe
    Member

    resolved in #36265 🎉

    we now use #imports/server ....

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

    types🔨 p3-minor

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions