使用Firebase Hosting部署NextJS应用时提示找不到pages目录求助
Firebase Hosting部署NextJS应用报错:找不到pages目录
我使用Firebase Hosting部署基于NextJS的Web应用,2023年3月底还能正常部署,但现在执行firebase deploy --only hosting命令时,明明在包含pages目录的项目根目录运行,却报错:“Couldn't find a pages directory. Please create one under the project root”。其他Firebase服务初始化正常,但Cloud Functions部署失败。
部署报错日志
+ functions: .firebase\myprojectprod\functions folder uploaded successfully i hosting[myprojectprod]: beginning deploy... i hosting[myprojectprod]: found 109 files in .firebase\myprojectprod\hosting + 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: > myprojectprod@0.3.0 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...
相关配置
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, }, })
项目目录结构
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/ ...
已尝试的解决方法
- 查阅Stack Overflow相关问题
- 执行干净部署流程:git克隆项目、npm install、firebase init、firebase deploy --only hosting
- 部署前运行
firebase experiments:enable webframeworks - 删除部署时自动生成的Cloud Functions函数
- 在firebase.json中添加
"public": "public"配置
内容的提问来源于stack exchange,提问作者engineer-x
相关产品推荐
相关产品推荐

