I am trying to convert my existing react app with next.js. Is it a right thing to do?

Viewed 206

We have created project in react-redux using firebase auth and solr DB.

below is the current folder structure of our App.

--src
    --actions
    --assets
    --components
    --controllers
    --firebase
    --reducers
    --utils
    --app.js

Now, to convert app to next js, I added the next js in dependencies and changed the scripts as below

 "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start"
  },

Now, I created directory "pages" in "src" folder and added the "index.js" hello world react program to test the next js and it worked by running the script "npm run dev"

So, I copied all folders from "controllers" to the "pages" folder and tried to access the static page "about"

Here, I'm getting below error,

sometime this error:

Firebase: Firebase App named '[DEFAULT]' alreadyexists (app/duplicate-app).

and on same page after reloading some time this error:

FirebaseError: projectId must be a string in FirebaseApp.options

What other things to do more to convert existing react app to next.js?
1 Answers

I see this firebase error in Next.js and React Native many times. I think it has something to do with render or something, but here is the solution:

firebase.js


import firebase from 'firebase/app';
import 'firebase/firestore';
import 'firebase/auth';

let config = {
  // your config
};

export default !firebase.apps.length
  ? firebase.initializeApp(config)
  : firebase.app();
Related