Repository navigation
Closed
Labels
Description
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' --noEmitAdditional context
No response
Logs
No response
Reacted by Peter Graugaard, Alex, Hiratake, Ed Rosewright, Thimo Sietsma, Sandro Circi, JD Solanki, Quentin Guerrier and Mares
Activity
github-actions commentedon Oct 3, 2024
Stackblitz link for the reproduction: Stackblitz
danielroe commentedon Oct 6, 2024
Probably we need to update typecheck to run
vue-tsctwice - one with root tsconfig and another with tsconfig in server dir. Does it work if you do that manually?Barbapapazes commentedon Oct 6, 2024
tsconfig.server.jsonwithskipLibCheck: truebut then I partially works because it continue to typecheck the app folder`vue-tsc` logs
app, I still have the same error`vue-tsc` logs
Barbapapazes commentedon Oct 6, 2024
In the
tsconfig.server.json, the line 115 (see screenshot above) that cause an issue. After removing it, no more errorBobbieGoede commentedon Jan 19, 2025
FYI - I don't think we can remove the
../**/*include entry intsconfig.server.jsonwithout changes to nitro, see https://github.com/nitrojs/nitro/blob/v2/src/core/build/types.ts#L274add TS ignores for authorize method
andy/iss 13 add direction to route (#31)
danielroe commentedon Jun 26, 2025
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
useRuntimeConfigin Nuxt, oruseSanityin@nuxtjs/sanityHaving said that, with the merge of #30665 (for v4) we are much closer and we support a single typechecking step.
nuxi typecheckdoes not works with alias imports (server) cli#455 as a duplicate of this issuenuxt typecheckconflates app and server auto-imports #35185 as a duplicate of this issuechairulakmal commentedon Aug 12, 2026
Hi @Barbapapazes
#36039 might help here. It adds an
#imports/serveralias 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:Your two
authorizekeep their own signature, so you don't have to make them the same.It does not fix plain
#importsin 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.
danielroe commentedon Sep 6, 2026
resolved in #36265 🎉
we now use
#imports/server....