Facing an issue while setting up firebase-admin SDK on my nextjs + TS project. Every time I try to call a SDK function, I encounter a webAssembly error. Specifically, when trying to configure a middleware for the server-side API and calling the verifyIdToken method, the error is thrown. Any suggestions on how to resolve this? Has anyone else encountered similar errors?
Here is the content of my middleware.ts
file:
import { auth } from "./lib/config/firebaseConfig";
import { NextResponse } from "next/server";
import { NextRequest } from "next/server";
interface ExtendedNextRequest extends NextRequest {
uid?: string;
}
export async function middleware(req: ExtendedNextRequest, res: NextResponse) {
try {
let token = req.headers.get("Authorization");
if (!token)
return NextResponse.json({ message: "Access Denied" }, { status: 403 });
if (token.startsWith("Bearer ")) {
token = token.split(" ")[1];
}
let decodedToken = await auth.verifyIdToken(token);
let uid = decodedToken.uid;
req.uid = uid;
return NextResponse.next();
} catch (error: any) {
console.log(error.errorInfo);
return NextResponse.json({ message: "Invalid Token" }, { status: 401 });
}
}
The error message I am encountering is as follows:
⨯ ./node_modules/farmhash-modern/bin/bundler/farmhash_modern_bg.wasm
Module parse failed: Unexpected character '' (1:0)
The module seem to be a WebAssembly module, but module is not flagged as WebAssembly module for webpack.
BREAKING CHANGE: Since webpack 5 WebAssembly is not enabled by default and flagged as experimental feature.
You need to enable one of the WebAssembly experiments via 'experiments.asyncWebAssembly: true' (based on async modules) or 'experiments.syncWebAssembly: true' (like webpack 4, deprecated).
For files that transpile to WebAssembly, make sure to set the module type in the 'module.rules' section of the config (e. g. 'type: "webassembly/async"').
(Source code omitted for this binary file)
Import trace for requested module:
./node_modules/farmhash-modern/bin/bundler/farmhash_modern_bg.wasm
./node_modules/farmhash-modern/bin/bundler/farmhash_modern.js
./node_modules/farmhash-modern/lib/browser.js
./node_modules/firebase-admin/lib/remote-config/condition-evaluator-internal.js
./node_modules/firebase-admin/lib/remote-config/remote-config.js
./node_modules/firebase-admin/lib/app/firebase-namespace.js
./node_modules/firebase-admin/lib/default-namespace.js
./node_modules/firebase-admin/lib/index.js
./lib/config/firebaseConfig.ts