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):
@marlonmarcello can you share your folder .graphqlconfig.yml contents? I am having trouble reproducing the issue with the schema your provided
It's on a private project, can I share that through email? Maybe dropbox or something?
Sure you can email [email protected] make sure you mention the issue number in the subject
Sent. Thank you @ammarkarachi
@marlonmarcello I was unable to reproduce but can you check if you have the necessary permissions on '/Volumes/projects/prototypes/amp-bug' ?
I do also that same issue is happening on another project on a different
place on my machine.
That is strange. I tried removing and installing the cli multiple times.
On Tue, May 26, 2020 at 3:40 PM Ammar notifications@github.com wrote:
@marlonmarcello https://github.com/marlonmarcello I was unable to
reproduce but can you check if you have the necessary permissions on
'/Volumes/projects/prototypes/amp-bug' ?—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/aws-amplify/amplify-cli/issues/4375#issuecomment-634317946,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAO5UYDFIFZN4MHPUZWYE5LRTRAMJANCNFSM4NK4TV2A
.
I'm getting the same error today - version 4.21.0
I also experienced this when running amplify mock
on 4.21.0. I had made no changes to a schema that I was working on last week. The only change was the upgrade.
I downgraded to 4.20.0 and amplify mock
now successfully starts the mock service.
Environment: MacOS 10.15.4 (Catalina)
Node version: 12.16.2
@benmj you are right. Reverting back to 4.20.x fixes this.
What else can I do to help @ammarkarachi ?
@marlonmarcello
I have the mock running with the following settings with your project are these the values you are using?
GraphQL schema compiled successfully.
Edit your schema at .....amp-bug/amplify/backend/api/ampbug/schema.graphql or place .graphql files in a directory at .../amp-bug/amplify/backend/api/ampbug/schema
Creating new table ProjectTable
Creating new table ConceptTable
Creating new table PageTable
Running GraphQL codegen
? Choose the code generation language target javascript
? Enter the file name pattern of graphql queries, mutations and subscriptions src/graphql/**/*.js
? Do you want to generate/update all possible GraphQL operations - queries, mutations and subscriptions Yes
? Enter maximum statement depth [increase from default if your schema is deeply nested] 2
✔ Generated GraphQL operations successfully and saved at src/graphql
AppSync Mock endpoint is running at http://localhost:20002
Yes. I have the default options as well.
I tried again but with no luck. v4.21
is broken for me.
Also experiencing this in 4.21.0
Downgrading to 4.20.0
fixed the issue
Here is additional information @ammarkarachi @marlonmarcello
^X^C(node:29546) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'stop' of undefined at APITest.(/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-util-mock/lib/api/api.js:82:41) at Generator.next ( ) at /usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-util-mock/lib/api/api.js:8:71 at new Promise ( ) at __awaiter (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-util-mock/lib/api/api.js:4:12) at APITest.stop (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-util-mock/lib/api/api.js:66:16) at APITest. (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-util-mock/lib/api/api.js:36:32) at Generator.next ( ) at /usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-util-mock/lib/api/api.js:8:71 at new Promise ( ) (node:29546) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3) (node:29546) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
@marlonmarcello Can you IM me on our discord community so I can reproduce this issue?
@dwamianm Can you share your schema?
@dwamianm this seems to be a different issue from the stack trace. Could you try clearing the ESM cache by deleting /usr/local/lib/node_modules/@aws-amplify/cli/node_modules/.cache/esm
and see if you still have the same issue
I think that link expired @ammarkarachi
@yuth when I do npm -g remove @aws-amplify/cli
that folder is gone
@yuth when I do
npm -g remove @aws-amplify/cli
that folder is gone
THE ESM cache removal was one possible solution for this and not the original issue.
^X^C(node:29546) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'stop' of undefined
at APITest. (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-util-mock/lib/api/api.js:82:41)
at Generator.next ()
at /usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-util-mock/lib/api/api.js:8:71
at new Promise ()
at __awaiter (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-util-mock/lib/api/api.js:4:12)
at APITest.stop (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-util-mock/lib/api/api.js:66:16)
at APITest. (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-util-mock/lib/api/api.js:36:32)
at Generator.next ()
at /usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-util-mock/lib/api/api.js:8:71
at new Promise ()
(node:29546) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag--unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:29546) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
The original issue has to do something with CFN parsing and it would make it easier if we could get the stack trace.
I removed the cli, deleted the project, cleared npm cache and removed all folders from the npm bin.
Then I proceeded to install the cli again, and start a new project with the schema above and I still got the same issue on 4.21
Failed to start API Mock endpoint TypeError: Cannot read property '0' of null
@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 line yield 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.js
things 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 java
on my machine which seems to have fixed the issue.
@marlonmarcello @ammarkarachi FYI
That was it!
Thanks a lot @dwamianm !!
just as fyi, Issue is still happening on amplify version 4.21.3 on Catalina 10.15.5,
brew cask reinstall java
also fixed the issue for me
Most helpful comment
@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.js
things 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 java
on my machine which seems to have fixed the issue.@marlonmarcello @ammarkarachi FYI