next-auth icon indicating copy to clipboard operation
next-auth copied to clipboard

'SessionProvider' only refers to a type, but is being used as a value here. In Typescript project

Open Squirrelcoding opened this issue 5 years ago • 15 comments

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

  1. npx create-next-app --typescript
  2. In your app.tsx file, 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 📽

image

image 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

Squirrelcoding avatar Oct 23 '21 16:10 Squirrelcoding

Never mind, just use

import { Provider } from "next-auth/client"

source

Squirrelcoding avatar Oct 23 '21 16:10 Squirrelcoding

Just in case someones come across this issue, make sure the file extension is .tsx not .ts

ludbek avatar Jun 10 '23 03:06 ludbek

Just in case someones come across this issue, make sure the file extension is .tsx not .ts

Lol, it actually happened to me

RasonYudha4 avatar Jun 15 '23 20:06 RasonYudha4

Just in case someones come across this issue, make sure the file extension is .tsx not .ts

LOL. I looked at that 15 times and still didn't catch my .tsx vs .ts mistake.

Thanks!

cbmeeks avatar Jul 20 '23 17:07 cbmeeks

Just in case someones come across this issue, make sure the file extension is .tsx not .ts

Lol, it actually happened to me

same here

TUTI254 avatar Aug 02 '23 09:08 TUTI254

change the .ts file to .tsx then it will works 100%

mhmd-aashik avatar Nov 14 '23 20:11 mhmd-aashik

Just in case someones come across this issue, make sure the file extension is .tsx not .ts

ohhhh thanks

VaibhavKambar7 avatar Feb 08 '24 14:02 VaibhavKambar7

Holy shit , just faced this stupid error, My god this .ts and .tsx bug😮

shoaibkh4n avatar Feb 19 '24 10:02 shoaibkh4n

Thankyou for the help @ludbek . Happened same for me, it was ts and not tsx.

adarsh786-tech avatar Apr 10 '24 14:04 adarsh786-tech

Just in case someones come across this issue, make sure the file extension is .tsx not .ts

God ! thanks a ton

andreconghau avatar Jun 05 '24 07:06 andreconghau

Just in case someones come across this issue, make sure the file extension is .tsx not .ts

Thanks Man It worked!

raunak-mishraa avatar Jul 19 '24 15:07 raunak-mishraa

change the .ts file to .tsx then it will works 100%

Thanks

shekhtausif8090 avatar Sep 17 '24 13:09 shekhtausif8090

Just in case someones come across this issue, make sure the file extension is .tsx not .ts

Thanks

LakshanRukantha avatar Oct 22 '24 20:10 LakshanRukantha

Just in case someones come across this issue, make sure the file extension is .tsx not .ts

Thanks bro, I might not found that mistake

Onkar3107 avatar Sep 05 '25 06:09 Onkar3107

it just a simple thing make sure file name is tsx not ts

akhan492 avatar Oct 31 '25 16:10 akhan492