【发布时间】:2020-06-23 10:22:36
【问题描述】:
正如标题所说,目前我无法从我的终端部署功能。我想正常部署功能。看来 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文件有问题吗??
【问题讨论】:
-
你在构建脚本中使用过
next build吗?你能显示完整的 package.json 吗? -
更新了帖子。我基本上使用了
npm run deploy的脚本。我执行时不使用next build -
Nextjs 要求您使用
next build,因为它会创建项目的构建版本,然后您可以部署它。 -
感谢您的快速解释。
next build src/functions将在 dist 文件夹中创建一个构建版本,然后它就可以部署了? -
点击
next build src/functions会在下一个Couldn't find a `pages` directory. Please create one under the project root出错,这可能是什么问题?