[英]Functions is not deployed correctly with an error saying that 'could not find a valid build'
正如標題所說,目前我無法從我的終端部署功能。 我想正常部署功能。 看來 Next 來了。
我的項目文件夾目錄結構如下:
- root
- dist
- src
- app
- functions <- I only want to deploy this folder to Cloud Functions
- public
- node_modules
- package.json
- jest.config.js
- firebaserc
And other setting files are managed here
這是 firebase.json
{
....
"functions": {
"predeploy": [
"npm run lint",
"npm run build"
],
"source": "."
},
...
}
這是我的 package.json
{
"name": "functions",
"scripts": {
"dev": "NODE_ENV=development next src/app",
"clean": "rimraf dist",
"build:app": "npm run clean && NODE_ENV=development next build src/app",
"build:app:prod": "npm run clean && NODE_ENV=production next build src/app",
"start:app": "next start src/app",
"lint": "tslint --project src/functions/tsconfig.json",
"build": "tsc --project src/functions",
"serve": "npm run build && firebase emulators:start --only functions,hosting",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "npm run build && firebase deploy --only functions",
"deploy:hosting": "firebase deploy --only functions:hosting",
"logs": "firebase functions:log"
},
"main": "dist/functions/index.js",
"dependencies": {.....}
}
這是執行腳本時下面控制台中的錯誤消息所說的:
Running command: npm run build
> functions@ build /Users/{user}/Desktop/{project}
> tsc --project src/functions
✔ functions: Finished running predeploy script.
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
✔ functions: required API cloudbuild.googleapis.com is enabled
✔ functions: required API cloudfunctions.googleapis.com is enabled
i functions: preparing . directory for uploading...
Error: Error occurred while parsing your function triggers.
Error: Could not find a valid build in the '/Users/{user}/Desktop/{project}/dist/functions/next' directory! Try building your app with 'next build' before starting the server.
我不知道為什么會出現這個錯誤? 我在這里做錯了什么? 配置/json文件有什么問題嗎?
我建議你先閱讀官方的 nextjs教程。
您使用 nextjs 以便您的網站頁面在服務器而不是客戶端中生成,在構建時 (SSG) 或請求時 (SSR) 預渲染頁面,這主要是為了使網站 SEO 友好。 這就是為什么您需要在根目錄中包含所有頁面的 pages 目錄。
你的腳本也需要修改,它至少應該有如下內容:
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
這樣,當您執行npm build
時,nextjs 將構建您項目的“構建版本”,您可以稍后部署。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.