Amplify部署NextJS报错:无法初始化production环境类别(path参数未定义)
问题:AWS Amplify部署Backend步骤失败,提示路径参数未定义
项目环境
- Amplify CLI版本:10.5.1
- NextJS版本:12.1.5-canary.7
- 配置:GitHub
production分支关联Amplifyproduction环境,自动部署,后端使用Amplifyproduction环境做身份验证,已正常运行2个月。
错误现象
部署卡在Backend步骤,关键错误:
Could not initialize categories for 'production': The "path" argument must be of type string. Received undefined
完整错误日志:
2022-12-08T06:22:40.740Z [INFO]: [0mAmplify AppID found: d3k4n880hbvmjg. Amplify App name is: my-project-app-name[0m 2022-12-08T06:22:40.787Z [INFO]: [0mBackend environment production found in Amplify Console app: my-project-app-name[0m 2022-12-08T06:22:41.228Z [WARNING]: - Fetching updates to backend environment: production from the cloud. 2022-12-08T06:22:41.510Z [WARNING]: - Building resource auth/coursemapfrontend 2022-12-08T06:22:41.550Z [WARNING]: ✔ Successfully pulled backend environment production from the cloud. 2022-12-08T06:22:41.905Z [WARNING]: ✖ There was an error initializing your environment. 2022-12-08T06:22:41.907Z [INFO]: 🛑 Could not initialize categories for 'production': The "path" argument must be of type string. Received undefined 2022-12-08T06:22:41.907Z [INFO]: Resolution: Review the error message and stack trace for additional information. Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/ 2022-12-08T06:22:41.908Z [INFO]: 2022-12-08T06:22:41.909Z [INFO]: Session Identifier: f49926f2-49c5-4601-95c3-f5a9c63375d9 2022-12-08T06:22:42.524Z [ERROR]: !!! Build failed 2022-12-08T06:22:42.524Z [ERROR]: !!! Non-Zero Exit Code detected 2022-12-08T06:22:42.524Z [INFO]: # Starting environment caching... 2022-12-08T06:22:42.524Z [INFO]: # Uploading environment cache artifact... 2022-12-08T06:22:42.581Z [INFO]: # Uploaded environment cache artifact 2022-12-08T06:22:42.582Z [INFO]: # Environment caching completed Terminating logging...
解决方法
- 检查Amplify后端配置文件:本地拉取最新后端环境,查看
amplify/backend/auth/<你的auth资源名>下的parameters.json和template.json,确认是否存在值为undefined的路径相关字段,修复后提交代码。 - 清理Amplify构建缓存:在Amplify控制台对应环境页面,找到Build settings,点击Clean build cache,之后重新触发部署。
- 升级Amplify CLI:本地执行
npm install -g @aws-amplify/cli@latest升级到最新稳定版,提交依赖变更后重新部署。 - 重新关联后端环境:本地执行
amplify env remove production,再用amplify env add production重新关联云端环境,确认配置无误后提交代码。 - 检查项目结构变更:确认近期是否修改过NextJS项目目录结构或路径配置,若有调整需确保Amplify构建脚本能正确识别路径。
内容的提问来源于stack exchange,提问作者Ankit Sanghvi
相关产品推荐
相关产品推荐

