amplify-cli: Failed to start API Mock endpoint Typerror
Describe the bug
Trying to mock the API returns an error that is untraceable and not very unhelpful.
Failed to start API Mock endpoint TypeError: Cannot read property '0' of null
Amplify CLI Version cli version: 4.21.0 amplify version: 3.0.11
To Reproduce
mkdir amplify-bug
cd amplify-bug
amplify init
amplify add auth <= default config
amplify add api <= graphql default config
Use the following schema:
type Project
@model
@auth(
rules: [
{ allow: groups, groups: ["Reg", "Admin"] }
{ allow: groups, groupsField: "client", operations: [read] }
]
)
@key(name: "ByClient", fields: ["client"], queryField: "projectsByClient")
@key(name: "BySlug", fields: ["slug"], queryField: "projectsBySlug") {
id: ID!
title: String!
slug: String!
client: ClientGroupEnum!
description: String
logo: S3Object
concepts: [Concept]
@connection(keyName: "byConcept", fields: ["id"], sortField: "createdAt")
}
enum ClientGroupEnum {
Reg
Aux
Tyt
}
type Concept
@model(queries: null)
@key(name: "byConcept", fields: ["projectID"])
@auth(
rules: [
{
allow: groups
groups: ["Admin", "Reg"]
operations: [create, update, delete]
}
]
) {
id: ID!
name: String!
projectID: ID!
moodboard: S3Object
pages: [Page]
@connection(keyName: "byPage", fields: ["id"], sortField: "createdAt")
}
type Page
@model(queries: null)
@key(name: "byPage", fields: ["conceptID"])
@auth(
rules: [
{
allow: groups
groups: ["Admin", "Reg"]
operations: [create, update, delete]
}
]
) {
id: ID!
name: String!
size: PageSizeEnum!
conceptID: ID!
image: S3Object!
}
type S3Object {
key: String!
identityId: String!
}
enum PageSizeEnum {
Small
Medium
Large
}
Expected behavior Mock API endpoint working
Desktop (please complete the following information):
- OS: Mac
- Node Version: v12.16.2
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 22 (7 by maintainers)
@yuth . I tried removing the cache as you recommended and then I removed the cli all together. I then generated a brand new project with minimal schema file. The issue continued to happen so I followed the output I posted earlier and found where things were failing.
The issue seems to be happening in the method
checkJavaVersion. When I comment out the lineyield index_1.checkJavaVersion(context);in the generated JS file/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-util-mock/lib/api/api.jsthings worked. Which means it was failing at the Java version check.I ended up digging up this related issue.
https://github.com/aws-amplify/amplify-cli/issues/3319
Since Java was already installed on my Mac, I ran
brew cask reinstall javaon my machine which seems to have fixed the issue.@marlonmarcello @ammarkarachi FYI
just as fyi, Issue is still happening on amplify version 4.21.3 on Catalina 10.15.5,
brew cask reinstall javaalso fixed the issue for me@benmj you are right. Reverting back to 4.20.x fixes this. What else can I do to help @ammarkarachi ?