-
Notifications
You must be signed in to change notification settings - Fork 375
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
Farmhash-modern throws webassembly error in Nextjs #2627
Comments
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight. |
Does configuring webpack by setting module.exports = {
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
config.experiments = {
asyncWebAssembly: true,
};
return config;
},
}; |
I'm getting the same issue.. This code does seem to "fix" the issue, but
|
Experiencing the same issue. For now, I followed the workaround at #2552 (comment), which is to downgrade to Credits to @chandrasekhar2039 |
Downgrading to 12.0.0 did not work for me.
|
I also tried this, but as @Keegan-lee said |
I am experiencing the same exact issue. Workaround Also, using Edit: use |
I am guessing that Firebase Auth cannot be used on Edge runtime due to the need for some Node-only modules. |
Hey Guys, |
You shouldn’t get the error, the package should be able to smoothly run on all NextJS environments. I however renew my suggestion of being cautious when using the package |
Are you sure? I see plenty of people complaining about the same thing (that it won't work when using middleware). I'm using firestore and admin (but not auth) from firebase-admin and it leads to that error. |
How are you importing the library? Also, yes I am sure, as per the documentation of the package:
|
Here is my middleware,
and here is the stack trace,
and here is the content of firebase-init.ts file:
|
updated my response above. |
As pointed out earlier, Firebase seems to work only in the Node server. // /api/auth/session export async function GET(_request: Request){ // middleware.ts console.log(isAuthenticated) const respond = NextResponse.next() return respond |
First of all, I suggest that you all try to format the code in the thread correctly. You can do so via backticks. @hassanzadeh I can't test your code right now, but the issue might lie in the fact that you are still using @brouza Seems like an okay workaround as far as I'm concerned; you could even try using a server action to abstract away the REST paradigm. I would at least try to secure the endpoint, however, even though it's a server-to-server communication. There might be more security implications as well. I am as well awaiting an official response regarding this issue. |
Thanks @nicolopadovan , |
Thanks, I first need to know why my current code is not working especially that I'm not using firebase-admin auht at all. |
Ok, I think you are right. |
Use webassembly in middlewares is not common practice. Using native code means you are applying a complex solution to improve efficiency. Middleware in Next.js is designed for handling requests and responses, but your approach may be misusing it. In the case of Firebase, it's best to separate the methods into distinct files, such as firebaseServerSide.ts and firebaseClientSide.ts. Again, middleware in Next.js does not support running WebAssembly, and it’s generally a bad practice to run this type of code there (since firebase-admin uses WebAssembly). My recommendation is to enhance your login and authentication processes. Consider implementing straightforward checks, such as validating tokens with JWT or other libraries, or even using libraries like next-auth for this purpose. Another important observation is that if you are using firebase-admin on the client side(or import methods that use firebase-admin), it is considered a bad practice and poses significant security risks, which will likely lead to similar problems. |
Thanks @rwlp for the insight. I did some research and understand the issue better. |
Same error when using 12.6.0 |
We removed the dependency on |
Still running into the same issue from my end. Exact same scenario as OP, I have a middleware which is checking if the JWT is valid, |
[REQUIRED] Step 2: Describe your environment
[REQUIRED] Step 3: Describe the problem
I'm trying to configure firebase-admin SDK on my nextjs + TS project. Whenever i try to invoke any SDK function, i get a webAssembly error. In my case, i am trying to configure a middleware for the server side api, and when i call the verifyIdToken method it throws the error. I'll paste it below, i also noticed that the affected dependency
farmhash-modern
was just replaced in this version of firebase.Steps to reproduce:
The error occured when i called the
verifyIdToken()
method in mymiddleware.ts
file.Relevant Code:
This is the middleware file.
This is the error output
This question is also on stackoverflow
The text was updated successfully, but these errors were encountered: