Closed binajmen closed 3 years ago
I've found out the problem.
In the getServerSideProps
, I'm retrieving data from Firestore
using the admin SDK. In order to use the emulator in the development environment, you must set the .env
variable FIRESTORE_EMULATOR_HOST
to connect to the emulator running locally. Unfortunately, it was in my .env.local
and therefore pushed in the production Docker image... Therefore the connection was impossible.
Nevertheless, I don't understand why it pops a totally different error, that is: toLowerCase is undefined. Any idea how we could avoid obfuscating these kind of errors?
// pages/index.js
...
export const getServerSideProps = async (ctx: GetServerSidePropsContext) => {
try {
const vendorsRef = admin.firestore().collection('vendors')
const snapshot = await vendorsRef.get()
if (snapshot.empty) {
return { props: { vendors: [] } }
}
const docs: any = [] // TOFIX: define type
snapshot.forEach(doc => {
const { geopoint, ...rest } = doc.data()
docs.push({ id: doc.id, ...rest })
})
return {
props: {
vendors: docs
}
}
} catch (error) {
console.error(error)
return { redirect: { destination: '/404', permanent: false } }
}
}
# FIREBASE ADMIN LOCAL
FIRESTORE_EMULATOR_HOST=localhost:8080 // 👈 this caused the error
#FIREBASE_AUTH_EMULATOR_HOST=localhost:9099
Hey! I'm sorry you had an issue here but glad you found the solution 😄
This does seem like a problem that arose from your codebase, but I agree that error wasn't the most helpful. To be honest, I'm not sure a good way from the framework to detect the issue you presented (I included my .env.local
in production) because I'm not sure we could make an assumption that was definitely wrong for someone. We could throw a warning? But I'm not sure.
If you have a suggestion, I'm open. Otherwise, I'll close this one.
The warning message was misleading, but that's the beauty of code debugging I guess 😅 It's just weird that Firebase is not raising an error prior to this one..
In the end, the solution was to use env.local.development
which is clearly documented here.
I had the same issue and i disabled i18n in next.config to find out that i didnt correctly format my paths in getStaticPaths. i re-enabled i18n in next.config after fixing paths and its working .
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
What version of Next.js are you using?
10.0.7
What version of Node.js are you using?
14.15.5-buster
What browser are you using?
Chrome
What operating system are you using?
Docker image node:14.15.5-buster
How are you deploying your application?
Docker image on Google Cloud Platform using Cloud Run
Describe the Bug
I get the following errors and the page will not load:
Expected Behavior
I expect the page to be loaded.
To Reproduce
I can't provide a github repo as it is a private project, but see below some relevant files that could help.
Relevant files that could help: