mirror of
https://github.com/luxfi/bridge.git
synced 2026-09-24 00:26:46 +00:00
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:
@@ -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',
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user