I am currently developing a next.js web application and I have decided to utilize firebase for both database management and authentication. However, when attempting to import firebase in a specific file, I encountered the following error:
Error - ./firebase.js:1:0
Module not found: Package path . is not exported from package /home/naveen/New Folder/whatsapp-2/node_modules/firebase (see exports field in /home/naveen/New Folder/whatsapp-2/node_modules/firebase/package.json)
Did you mean './firebase'?
Requests that should resolve in the current directory need to start with './'.
Requests that start with a name are treated as module requests and resolve within module directories (node_modules).
If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.
> 1 | import firebase from "firebase";
2 |
3 | const firebaseConfig = {
4 | apiKey: "AIzaSyAS5PuV434Qb5IqgMHnte1UKha-31PjB-Y",
Import trace for requested module:
./pages/_app.js
https://nextjs.org/docs/messages/module-not-found
Below is the content of my firebase.js file:
import firebase from "firebase";
const firebaseConfig = {
apiKey: "AIzaSyAS5PuV434Qb5IqgMHnte1UKha-31PjB-Y",
authDomain: "whatsapp-2-b5a79.firebaseapp.com",
projectId: "whatsapp-2-b5a79",
storageBucket: "whatsapp-2-b5a79.appspot.com",
messagingSenderId: "960710517268",
appId: "1:960710517268:web:42e2b65fd273553966fd01",
};
const app = !firebase.apps.length
? firebase.initializeApp(firebaseConfig)
: firebase.app();
const db = app.firestore();
const auth = app.auth();
const provider = new firebase.auth.GoogleAuthProvider();
export { db, auth, provider };
Moreover, this here is the snapshot of my package.json file:
{
"name": "whatsapp-2",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@material-ui/core": "^4.12.3",
"@material-ui/icons": "^4.11.2",
"email-validator": "^2.0.4",
"firebase": "^9.0.0",
"next": "11.1.0",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-firebase-hooks": "^3.0.4",
"styled-components": "^5.3.1"
},
"devDependencies": {
"eslint": "7.32.0",
"eslint-config-next": "11.1.0"
}
}
Lastly, presented below is the exports field information from package.json within node_modules.firebase :
{ "exports": {
"./analytics": {
"node": {
"require": "./analytics/dist/index.cjs.js",
"import": "./analytics/dist/index.mjs"
},
"default": "./analytics/dist/index.esm.js"
},
"./app": {
...
}
...(more entries)...
},
}
In addition to installing firebase using yarn by running the command 'yarn add firebase', what steps might I be missing or doing incorrectly?