Stub Firebase modules during server-side build

Next.js evaluates all modules during build for page data collection,
including the layout which transitively imports Firebase through
@luxfi/ui and @hanzo/auth. Firebase's initializeApp() fails because
real credentials aren't available at build time.

This adds webpack aliases that redirect Firebase imports to a stub
module during server-side production builds. The real Firebase modules
still load normally in the browser at runtime.
This commit is contained in:
2026-02-24 03:29:26 -08:00
parent f106fee594
commit 37becdd282
2 changed files with 33 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
// Stub for Firebase modules during server-side build
// Firebase is a client-only dependency that fails during Next.js build
// because initializeApp() requires credentials not available at build time.
const noop = () => {}
const noopAsync = () => Promise.resolve()
const noopObj = new Proxy({}, { get: () => noop })
const app = { name: '[DEFAULT]', options: {}, automaticDataCollectionEnabled: false }
module.exports = {
initializeApp: () => app,
getApp: () => app,
getApps: () => [app],
deleteApp: noopAsync,
onLog: noop,
setLogLevel: noop,
SDK_VERSION: '0.0.0-stub',
}
+14
View File
@@ -76,6 +76,20 @@ module.exports = (phase, { defaultConfig }) => {
config.externals.push("pino-pretty", "lokijs", "encoding");
config.resolve.fallback = { fs: false, net: false, tls: false };
config.resolve.alias['@'] = path.resolve(__dirname, 'src');
// Stub Firebase modules during server-side build to prevent
// "default Firebase app does not exist" errors at build time.
// Firebase is client-only; real modules load at runtime in browser.
if (isServer && !dev) {
const firebaseStub = path.resolve(__dirname, 'next-conf/firebase-stub.js');
config.resolve.alias['firebase/app'] = firebaseStub;
config.resolve.alias['firebase/firestore'] = firebaseStub;
config.resolve.alias['firebase/auth'] = firebaseStub;
config.resolve.alias['firebase/analytics'] = firebaseStub;
config.resolve.alias['firebase/storage'] = firebaseStub;
config.resolve.alias['@firebase/app'] = firebaseStub;
}
let conf = svgrPluginConfig(config)
// if (dev) {
// conf = watchPluginConfig(conf)