Skip to content
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

Build issue: Node's own modules are being transpiled, which results in a broken build #331

Closed
awthwathje opened this issue Jan 7, 2021 · 3 comments

Comments

@awthwathje
Copy link

Hello, I'm using Next.js with Auth0 integration and its @auth0/nextjs-auth0 package depends on jose v1. This has an unfortunate side effect of FAB not being able to produce a working build.

That is, yarn next build && yarn next start works fine, whereas yarn next build && yarn fab build && yarn fab serve fails with TypeError: getCurves is not a function error.

This is a known issue with jose v1, and its maintainer says:

don’t transpile crypto

and

<...> tells me that you transpile your dependencies. Stop doing so and you'll be fine, its likely that even node's crypto is polyfilled for you which is why you get the error

panva/jose#93 (comment), panva/jose#72 (comment).

Which leads me to an assumption. that FAB transpiles Node's own modules during the build, which in some cases is not desirable (I use Node 15.5.1).

Any chance to look into this? Since Next.js' own builder doesn't seem to have this issue, maybe some hints could be taken from it.

@awthwathje awthwathje changed the title Build issue: Node's own modules are being transpiled Build issue: Node's own modules are being transpiled, which results in broken build Jan 7, 2021
@awthwathje awthwathje changed the title Build issue: Node's own modules are being transpiled, which results in broken build Build issue: Node's own modules are being transpiled, which results in a broken build Jan 7, 2021
@geelen
Copy link
Contributor

geelen commented Feb 17, 2021

Hi @awthwathje, sorry for the delay in getting back to you, did you manage to get this working at all?

We've had problems with Next plugins in the past: #258

Basically, the whole NextJS ecosystem assumes a full NodeJS runtime, so plugins are usually incompatible with FABs. In this case I think we do need to compile crypto since the NodeJS one isn't accessible within a FAB. I might be wrong, but maybe we can add a browser-compatible crypto shim to this section https://github.com/fab-spec/fab/blob/master/packages/input-nextjs/src/build.ts#L107-L113 ?

How easy is this to reproduce? Does it occur as soon as you spin up a fresh NextJS app and add @auth0/next-auth0?

@loklaan
Copy link

loklaan commented Mar 25, 2021

I spent a few hours today trying to get @auth0/next-auth0 working. I almost got it there by:

  • Adding to shims in input-nextjs/src/build.ts for more native modules (dns, http2, tls)
  • Patching the crypto-browserify package with missing crypto exports (generateKeyPair, generateKeyPairSync stub, getCurves).

I ended up giving up on dynamic nextjs 😅, and instead will be just writing dynamic behaviours into custom FAB plugins, because my server.js ended up being over 10mb (unrelated). Thought it might be worth mentioning the above specifics for the next (lol) person though!

@awthwathje
Copy link
Author

awthwathje commented Apr 27, 2021

Hi @awthwathje, sorry for the delay in getting back to you, did you manage to get this working at all?

No, I didn't and the Auth0 SDK had changed recently, and this particular issue is gone now. But it depends on Node.js API and since Workers aren't yet Node.js-compatible, I'm looking for another server-side auth integration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants