blitz-js / babel-plugin-superjson-next

Automatically transform your Next.js Pages to use SuperJSON
MIT License
125 stars 15 forks source link

Does this work with Next 11? #76

Closed edgarasben closed 3 years ago

edgarasben commented 3 years ago

Seems like this stopped working for me when updated to Next 11.0.0.

Did anybody run into a similar issue?

error - ./pages/index.js
SyntaxError: Unexpected token / in JSON at position 0
    at JSON.parse (<anonymous>)
Skn0tt commented 3 years ago

Hi @edgarasben! I tried updating our example to Next 11 in #78, and it works fine both locally and in CI. Could you provide a minimal reproduction repo? That'd make it a lot easier for me to reproduce.

tadeumaia commented 3 years ago

Same happening to me.

There is not much to my use. Just a next.js page with the following getServerSideProps. .babel.rc is the example one, user has a datetime field

I just hit this problem and was trying your pkg, and come here for help because it was not working.

Error: Error serializing .users[0].emailVerified returned from getServerSideProps in "/usuarios". Reason: object ("[object Date]") cannot be serialized as JSON. Please only return JSON serializable data types.

This error happened while generating the page. Any console logs will be displayed in the terminal window.

export const getServerSideProps: GetServerSideProps = async () => {
  const prisma = new PrismaClient()

  const users = await prisma.user.findMany()

  console.log(users)

  return {
    props: { users },
  }
}
edgarasben commented 3 years ago

Exactly what @tadeumaia described. I can try to post a minimal reproduction repo later.

Skn0tt commented 3 years ago

A repro would be great, thank you!

thomaszdxsn commented 3 years ago

I have not work issue, but fixed by change plugins: ["superjson-next"] to plugins: ["babel-plugin-superjson-next"]

Skn0tt commented 3 years ago

That sounds like a caching issue then. @edgarasben @tadeumaia have you tried deleting caches?

edgarasben commented 3 years ago

That sounds like a caching issue then. @edgarasben @tadeumaia have you tried deleting caches?

@Skn0tt am not an advanced developer, could you specify what do you mean by that in this case?

gleuch commented 3 years ago

I was running into issues as well when upgrading to Next v11 where it would no longer catch undefined prop values from getServerSideProps. This worked without issue in 10.2.3.

We're running with Express server and defined the working directory when initializing NextJS (const app = nextJS({ dir: './src' });).

When we removed dir parameter (src/pages is supported by default in Next), this resolved our issue with SuperJSON not processing.

Not entirely sure if that is helpful, but could be a starting point to look at issues with custom directories?

Skn0tt commented 3 years ago

could you specify what do you mean by that in this case?

Sure! Babel plugins such as babel-plugin-superjson-next transpile your code. For efficiency, they try to cache their work: If a piece of code has been transpiled once, it won't be transpiled again. Sometimes this means stale caches: Something changed so you'd want everything to be re-transpiled again, but it doesn't since it's cached. Deleting caches is the easiest way to work around this.

For Next applications, deleting the .next folder should be the easiest way to delete caches.

but could be a starting point to look at issues with custom directories?

A reproduction repository would be a great starting point.

knaitas commented 3 years ago

Had the same issue and can confirm that deleting .next folder a.k.a cleaning the cache helps to solve this :)

Skn0tt commented 3 years ago

Closing this, as it seems to be fixed by purging the cache :)

edgarasben commented 3 years ago

@Skn0tt sorry for the late reply. When it did not work I removed the script from my codebase. But most likely you are right. It's the old .next cache that might have caused the problem. I will try using the script in the future and report here again, in case the problems persist.