I’m using Firebase Hosting to deploy my web app which uses NextJS. In the last deploy in late March 2023 I was able to deploy with the following steps but now I get an error where the pages
directory is not found even though I am running the deploy command at the root of the project where pages
is.
firebase deploy --only hosting
But running the Firebase command, the process is successful in initiating other Firebase services.
+ functions: .firebasemyprojectprodfunctions folder uploaded successfully
i hosting[myprojectprod]: beginning deploy...
i hosting[myprojectprod]: found 109 files in .firebasemyprojectprodhosting
+ hosting[myprojectprod]: file upload complete
i functions: updating Node.js 16 function firebase-frameworks-myprojectprod:ssrmyprojectprod(us-central1)...
Build failed with status: FAILURE and message: > [email protected] build
> next build
...
> Build error occurred
Error: > Couldn't find a `pages` directory. Please create one under the project root
at Object.findPagesDir (/workspace/node_modules/next/dist/lib/find-pages-dir.js:86:19)
at /workspace/node_modules/next/dist/build/index.js:103:63
at async Span.traceAsyncFn (/workspace/node_modules/next/dist/trace/trace.js:79:20)
at async Object.build [as default] (/workspace/node_modules/next/dist/build/index.js:66:29). For more details see the logs at https://console.cloud.google.com/cloud-build/builds;region=us-central1/xxx?project=xxx.
Functions deploy had errors with the following functions:
firebase-frameworks-myprojectprod:ssrmyprojectprod(us-central1)
i functions: cleaning up build files...
Issue seems to be with Cloud Functions. I deleted the function created by the deploy command and a new one is created.
firebase.json
{
"hosting": {
"source": ".",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"frameworksBackend": {
"region": "us-central1"
}
},
"firestore": {
"rules": "firestore.rules"
}
}
next.config.js
module.exports = withBundleAnalyzer({
transpilePackages: ["@stripe/firestore-stripe-payments"],
i18n: {
locales: ["en"],
defaultLocale: "en"
},
images: {
remotePatterns: [
{
protocol: "https",
hostname: "storage.googleapis.com",
pathname: `/my-bucket`,
},
],
},
devIndicators: {
buildActivity: false,
},
})
Project directory
pages/
blogs/
[blogId].tsx
blog-index.tsx
index.js
catalog.tsx
login.tsx
account.tsx
404.js
500.js
public/
favicon.ico
images/
icon1.png
themes/
firebase.json
package.json
tsconfig.json
firestore.rules
firebase.ts
.env.production
.env.local
css/
components/
...
firebase_utils/
...
I’ve tried
- Couldn't find a `pages` directory. Please create one under the project root
- Clean deploy: git clone, npm install, firebase init, firebase deploy –only hosting
- Running
firebase experiments:enable webframeworks
before deploy command - Deleting the Cloud Functions function which generates on deploy
- Using the
"public": "public"
option in thefirebase.json
since the documentation says it’s required (I don’t think it is)
2
Answers
Okay it works now. What worked is the combination of deleting the function in Cloud Functions and updating Firebase tools with
npm install -g firebase-tools
Went into the firebase console, then the functions window (under the build dropdown) and deleted the older function.
then did
firebase deploy
that solved it