'SessionProvider' only refers to a type, but is being used as a value here. In Typescript project
Description 🐜
When I am using next-auth in my typescript project, I get an error when I have the following code in my _app.tsx file:
import type { AppProps } from 'next/app'
import { SessionProvider } from "next-auth/client";
function MyApp({ Component, pageProps: { session, ...pageProps } }: AppProps) {
return (
<SessionProvider session={session}>
<Component {...pageProps}/>
</SessionProvider>
)
}
export default MyApp
The project is fine but when I hover over SessionProvider in VSCode, I get the error:
'SessionProvider' only refers to a type, but is being used as a value here.ts(2693)
And this is a big problem when it comes to building the project for production as it raises an error!
Is this a bug in your own project?
Yes
How to reproduce ☕️
Create a new app
npx create-next-app --typescript- In your
app.tsxfile, enter the following code:
import type { AppProps } from 'next/app'
import { SessionProvider } from "next-auth/client";
function MyApp({ Component, pageProps: { session, ...pageProps } }: AppProps) {
return (
<SessionProvider session={session}>
<Component {...pageProps}/>
</SessionProvider>
)
}
export default MyApp
You will see that this raises an error!
Screenshots / Logs 📽
Yes its a type but I cant even use it in Typescript
Environment 🖥
System:
OS: Windows 10 10.0.19042
CPU: (4) x64 Intel(R) Core(TM) i3-1005G1 CPU @ 1.20GHz
Memory: 720.21 MB / 3.70 GB
Binaries:
Node: 14.18.1 - C:\Program Files\nodejs\node.EXE
npm: 6.14.15 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Spartan (44.19041.1266.0), Chromium (95.0.1020.30)
Internet Explorer: 11.0.19041.1202
npmPackages:
next: 11.1.2 => 11.1.2
next-auth: ^3.29.0 => 3.29.0
react: 17.0.2 => 17.0.2
Contributing 🙌🏽
No, I am afraid I cannot help regarding this
Just in case someones come across this issue, make sure the file extension is .tsx not .ts
Just in case someones come across this issue, make sure the file extension is
.tsxnot.ts
Lol, it actually happened to me
Just in case someones come across this issue, make sure the file extension is
.tsxnot.ts
LOL. I looked at that 15 times and still didn't catch my .tsx vs .ts mistake.
Thanks!
Just in case someones come across this issue, make sure the file extension is
.tsxnot.tsLol, it actually happened to me
same here
change the .ts file to .tsx then it will works 100%
Just in case someones come across this issue, make sure the file extension is
.tsxnot.ts
ohhhh thanks
Holy shit , just faced this stupid error, My god this .ts and .tsx bug😮
Thankyou for the help @ludbek . Happened same for me, it was ts and not tsx.
Just in case someones come across this issue, make sure the file extension is
.tsxnot.ts
God ! thanks a ton
Just in case someones come across this issue, make sure the file extension is
.tsxnot.ts
Thanks Man It worked!
change the .ts file to .tsx then it will works 100%
Thanks
Just in case someones come across this issue, make sure the file extension is
.tsxnot.ts
Thanks
Just in case someones come across this issue, make sure the file extension is
.tsxnot.ts
Thanks bro, I might not found that mistake
it just a simple thing make sure file name is tsx not ts
