blitz-js / babel-plugin-superjson-next

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

Does not work with modular export #81

Closed PierreAndreis closed 2 years ago

PierreAndreis commented 3 years ago

It seems that this plugin does not pick up getServerSideProps that are exported as below.

import {getServerSideProps} from "..";

export { getServerSideProps }
export default Page

Note that it works fine if we export as shown below, although less preferred

import {getServerSideProps: getServerSidePropsOriginal} from "..";

export const getServerSideProps = getServerSidePropsOriginal
export default Page
Skn0tt commented 3 years ago

Hi @PierreAndreis! This is caused by how our Babel replacement works, would you be interested in submitting a PR to add support for this?

vincaslt commented 2 years ago

I have the same issue when using getServerSideProps as a function declaration, which I think is common usage.

export async function getServerSideProps() {
  ...
}

I changed it to a const arrow function and it started working.

Skn0tt commented 2 years ago

Hi @vincaslt! That's surprising, as we do have a test for exactly this declaration:

https://github.com/blitz-js/babel-plugin-superjson-next/blob/87eb281243dceb8f1d7587e247bbe1172bb8a82a/test/pages/gSSP%20function%20declaration/code.js#L1

Could you open a new issue for this, and give some more context on when it happens? A reproduction case would be great.

Skn0tt commented 2 years ago

I have a feeling this could be fixed by #97 (published in v0.4.1), could you verify that?

Skn0tt commented 2 years ago

Closing preemptively, feel free to re-open.