-
-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot find module '#auth' or its corresponding type declarations. TS error #418
Comments
I've tracked this down to be a problem w/ having a {
"extends": "../.nuxt/tsconfig.server.json",
}
{
"compilerOptions": {
"forceConsistentCasingInFileNames": true,
"strict": true,
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Node",
"allowJs": true,
"resolveJsonModule": true,
"paths": {}
},
"include": [
"./types/nitro.d.ts",
"../**/*",
"../server/**/*"
]
} Ideally, {
"extends": "../.nuxt/tsconfig.server.json",
"include": [
".nuxt/types/auth.d.ts",
".nuxt/types/nitro.d.ts",
"./server/**/*"
]
} Alternatively: import { promises as fsp } from "node:fs";
import { resolve } from "path"
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
pages: true,
modules: [
'@nuxtjs/tailwindcss',
'@sidebase/nuxt-auth',
async (_, nuxt) => {
nuxt.hook("nitro:init", (nitro) => {
nitro.hooks.hook("compiled", async () => {
const tsconfigPath = resolve(nitro.options.buildDir, nitro.options.typescript.tsconfigPath);
const tsconfig = JSON.parse(await fsp.readFile(tsconfigPath, "utf8"));
tsconfig.include.push("./types/auth.d.ts");
await fsp.writeFile(tsconfigPath, JSON.stringify(tsconfig, null, 2));
})
});
}
]
}) Maybe we can integrate the latter? Relevant: unjs/nitro#1266 |
@purefunctor thanks for providing work-around for this issue, but now it doesn't update types for custom data in session. EDIT: |
Could you elaborate? Im having the same problem |
Please more instructions on this one. |
@FollowJack basically what you have to do is create a file in the
Address is an example value, and you should change it, to what you need inside user type. |
I had this issue out of the gate until I threw caution to the wind and built my project anyway... and since then it finds |
I got it to work using the following {
"extends": "../.nuxt/tsconfig.server.json",
"include": [
"../.nuxt/types/nitro.d.ts",
"../.nuxt/types/auth.d.ts",
"../server/**/*"
]
} |
This seems to solve the issue for me, but only partially. My types are recognized correctly in VSCode by applying this, but when running
Any suggestions? (Edit: hmm.. it looks like it's a different issue than the typing issue. I'll investigate a bit more tomorrow.) |
Well, it seems my typing issue has been resolved now. What I learned from this is that switching from the I also don't completely understand the approach of having two different "providers", that lead to different types in build time and runtime. I'm not an expert on nuxt plugins (yet), so maybe that's just me. |
Hi @gertjanjansen, We know that having two providers is not optimal, however we decided to introduce our own, as we had little to no control over how authjs handeled their systems. For example: We wanted to use static generation on one of our projects, something not supported by authjs, which is why we created our own local provider over which we have full control! I personally have no issues with VSCode detecting types, however this is different for every person. If you run into more issues, have a look here: https://sidebase.io/sidebase/resources/coding-setup We detail how we setup our machines internally. Maybe it helps! |
Hi! |
Hi @rowphant, I only closed the issue, as there was less activity on it! I would love to help you further:
I would summarize everything said before this with the following steps:
If all of these steps have not resolved your issue, I am going to need some kind of minimal replication of your project, where I can look into why the types are not working correctly. Also: I see this was your first message in this thread, what exactly is the issue you are currently facing? I have been trying to deduct it from your "thumbs up/thumbs down" reactions, but its a bit hard 😓 I would love to help you out and improve your Nuxt experience! |
To add to this, i had the same issue that In my case, the solution was even more stupid.. just regenerate the Granted, my environment is:
|
Hello everyone 👋 Due to my current cleanup of all issue I will propose the following steps to resolve this issue:
I think this should help people in the future not struggle with the same issue. |
Related to #596 |
Environment
Reproduction
Getting this error is as simple as just pasting
import { NuxtAuthHandler } from '#auth'
into[...].ts
file inserver/api/auth
directory.Describe the bug
It seems like TS can't find declaration for this module.
Additional context
I made sure it's not just an issue on my side, and tried it on 3 different machines (2 PCs and 1 VM) with Volar in takeover mode, as recommended by Nuxt, and still got the same results. I've tried to replicated this issue on Blitz, but failed in doing so. Here's link to repo: https://github.com/KitsuneKenshi/nuxt-auth-ts-error
Logs
No response
The text was updated successfully, but these errors were encountered: