NextJs SSR build fails deployment on Amplify

Viewed 627

I want to host and deploy a Next.js build that uses SSR pages on Amplify. The app builds in the local environment however, when I try to deploy it from the AWS/Amplify website by simply pushing updated file to Github repo. It does points out that it's a webpack error. PS. I'm using Firebase Firestore and Auth on the serverside and haven't set up anything for that to work with Amplify. Error points out to token

1 Answers

For those that come across build fails from deploying NextJs SSR apps with Firebase backend (Firestore,Auth,Analytics). I removed the split function error and I received another error about private key not being read correctly. I just added .replace(/\\n/g, '\n') to the private key field in the Firebase Admin initialization file.

if (!privateKey || !clientEmail || !projectId) {
    console.log(
      `Failed to load Firebase credentials. Follow the instructions in the README to set your Firebase credentials inside environment variables.`
    );
  }
  
  if (!firebaseAdmin.apps.length) {
    firebaseAdmin.initializeApp({
      credential: firebaseAdmin.credential.cert({
        privateKey: privateKey.replace(/\\n/g, '\n'),
        clientEmail,
        projectId,
      }),
    //   databaseURL: `https://${projectId}.firebaseio.com`,
    });
  }
Related