After update node version I get this error in next.config.js:
import { app } from './firebase';^^^^^^SyntaxError: Cannot use import statement outside a module
The same when I tried to use next/dynamic and require.
But when I delete import for app I have this:
const firestore = app.firestore(); ^ ReferenceError: app is not defined
I use next-pwa, CNA and I try to turn on enableIndexedDbPersistence and cacheSizeBytes for Firebase.Before update node wersion, I didn't have import and it was ok. Now isn't wrong.In another project I use yarn and this project npm.
My next config:
/** @type {import('next').NextConfig} */const withPWA = require("next-pwa");import('firebase/firestore').then(() => { const firestore = app.firestore(); // Use Cloud Firestore ... firestore().settings({ cacheSizeBytes: 400 }); firestore.enableIndexedDbPersistence() .catch((e) => { if (e.code === 'failed-precondition') { console.error(e.code) } else if (e.code === 'unimplemented') { console.error(e.code) } });});module.exports = withPWA({ reactStrictMode: true, i18n: { locales: ['en', 'jp', 'pl'], defaultLocale: 'en', }, images: { deviceSizes: [280, 320, 375, 425, 768, 1024, 1200, 1440, 2560], loader: 'default', domains: ['firebasestorage.googleapis.com', 's.yimg.com'], formats: ['image/avif', 'image/webp'], }, pwa: { dest: "public", register: true, skipWaiting: true, },});
My firebase.js:
import { initializeApp } from 'firebase/app';import { getAuth } from 'firebase/auth';import { getStorage } from 'firebase/storage';import { getFirestore } from 'firebase/firestore';const firebaseConfig = { apiKey: `${process.env.NEXT_PUBLIC_API_KEY}`, authDomain: `${process.env.NEXT_PUBLIC_AUTH_DOMAIN}`, projectId: `${process.env.NEXT_PUBLIC_PROJ_ID}`, storageBucket: `${process.env.NEXT_PUBLIC_STORAGE_BUCKET}`, messagingSenderId: `${process.env.NEXT_PUBLIC_SENDER_ID}`, appId: `${process.env.NEXT_PUBLIC_APP_ID}`};export const app = initializeApp(firebaseConfig);export const auth = getAuth(app);export const db = getFirestore(app);export const storage = getStorage(app);
Please help me.