-
-
Notifications
You must be signed in to change notification settings - Fork 172
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
CloudFlare Pages deployment fails with RollupError #378
Comments
+1 |
Hey @yu-kani 👋 Thanks for reporting:
I think this rather related to |
Hey @BracketJohn Thank you for your assistance. Repository where the error is reproducedhttps://github.com/yu-kani/nuxt-auth-test Pattern 1
Pattern 2
I am considering whether the cause lies in nuxt-auth or jose, but I do not have detailed knowledge and therefore do not know for sure. I am sorry. |
@BracketJohn I solved a similar error with cloudflare workers crypto compatibility. import {isDevelopment} from "std-env";
if (isDevelopment && typeof window === 'undefined') {
import('crypto').then(crypto => globalThis.crypto = crypto);
}
export default defineEventHandler(async event => {
const {uid} = getQuery(event);
const sharedSecret = 'a-secure-password';
const turnServer = 'turn.example.com';
const ttl = 86400;
const username = Math.floor(Date.now() / 1000) + ttl
const encoder = new TextEncoder();
const data = encoder.encode(username.toString());
const keyData = encoder.encode(sharedSecret);
const key = await crypto?.subtle?.importKey(
'raw',
keyData,
{ name: 'HMAC', hash: 'SHA-1' },
false,
['sign']
);
const signature = await crypto?.subtle.sign('HMAC', key, data);
const password = Buffer.from(signature).toString('base64');
// const password = base64url.encode(Buffer.from(new Uint8Array(signature)));
return {
username,
password,
ttl
};
}) |
I had this same issue in my nuxt deployment. I am not a javascript expert, but from looking at the dependencies it seems that jose is used by next-auth, which is a peer dependency with nuxt-auth. unenv, which seems to be a polyfilling library, is used by nitropack, which is used by nuxt-auth. unenv has now polyfilled the crypto library, but without the createHash and createHMAC functions. My solution was just to pin unenv to 1.2.2, which is the version before it added crypto support. I am not sure if there is a way to make a PR to unenv to like pass on the functions it doesnt polyfil, but I do not know enough about node or JS to do that. TL;DR -> hard pin/override unenv to be version 1.2.2 |
@jharris-tc thanks for the investigation. I'm still not getting a successful build myself. Environment
package
Result
|
and indeed looking at unenv the sourcecode says: // TODO: Add missing exports (typecheck is not working!) This is not an issue with nuxt-auth itself. |
here is my package.json
hopefully this helps, I just ran it again with seems like your versions might be ahead of mine, hope you can figure it out |
ah, thanks. i searched my eyes out trying to understand the overrides. -- edit -- from bad to worse i guess. Error: Failed to publish your Function. Got error: Uncaught TypeError: Object prototype may only be an Object or null: undefined i guess jose depends on more features implemented in newer version of unenv: node_modules/jose/dist/node/esm/runtime/is_key_object.js (3:20) "types" is not exported by "node_modules/unenv/runtime/node/util/index.mjs", imported by "node_modules/jose/dist/node/esm/runtime/is_key_object.js". the quickest fix for this would be unenv completing the missing crypto functions like createHash. thanks for the effort though, its appreciated. |
Can confirm this is an issue |
I get the types is not exported, unenv -> esm too, but it seems okay? I agree the cleanest fix is to unenv |
Until Unenv fixes it there end is there a temporary fix that could be implemented? |
This happens because next-auth is not really compatible with cloudflare workers out of the box. I've also documented some of the workaround that you need to fix some of the nitro/unenv build issues that you'll have due to authjs/pnpm/unenv https://github.com/Hebilicious/authjs-nuxt Maybe the sidebase team is interested into using this approach for a v1 ? |
Still getting this as well. Considering switching to @Hebilicious repo but that's a ton of work 😢 . |
What features do you need that are missing ? |
I don't think anything is missing - just complaining it is a lot of work to switch libraries. I just put together a proof of concept to investigate however! I left an issue on your repo that is a potential blocker for me, but maybe you've run into this before. Hebilicious/authjs-nuxt#43 |
@Otoris Thanks, just pushed a fix for this issue. |
I'm having this problem when trying to build cloudflare for Nuxt. When I import the ethers package, I have a problem because of the crypto package. @ethersproject/providers I tried to use it, this time I got the same error as yours. How can we solve the problem? |
You have to either migrate away from dependencies that require inbuilt node libraries (i.e. node:crypto) or you check which inbuilt node libraries are the root of the failed build (for Sidebase it is Node Crypto) and then hope that a polyfill is developed for that library. The gist of the error is that a dependency requires an inbuilt Node JS library, which is not present in a edge runtime environment such as Cloudflare Pages. Somebody then has to stich together a bridge between the NodeJS library and the edge environments (polyfill). Here is an incomplete polyfill of the Node Crypto library being worked on in the unenv project. |
In version 0.6, we introduced the I will go ahead and close this issue for now, as I don't see our team being able to futhur tackle this deployment issue. If an issue arrises with deploying the local providor to cloudflare, feel free to open a new issue and we can discuss it there! |
Would this mean that there is compatibility for using OAuth2 Providers? |
As mentioned by @Hebilicious, NextAuth, the OAuth package we use under the hood, does not support cloudflare workers, which means that with out current implementation, there will be no support for them, until NextAuth adds support. Sadly this means we are bound by their implementation and cannot overwrite or change this, unless we completly move away from their systems. |
Is there any plans to do that? |
With version 0.6, we do open the doors, to allow this, however re-implementing every oAuth provider, that NextAuth has, will take its time. We hope to be able to make NuxtAuth more extendable for others, that you could easily add the configuration for the oAuth provider you wish to use. But first, my goal is to iron out the last issues with 0.6 and get it released. Once we did this, I can discuss with the team what we could add to the roadmap. However, I do understand, this would be nice to add and have added it to my list! |
Environment
Reproduction
No response
Describe the bug
During the deployment process on CloudFlare Pages,an error is occurring because the jose package is unable to use the createHash function from the unenv package it depends on. Specifically, the digest.js file in the jose package is importing the createHash function from the crypto package, but it needs to retrieve createHash from the crypto module of the unenv package, which is not properly exported.
Additional context
I have tried the following and would like to report an issue:
Logs
The text was updated successfully, but these errors were encountered: