aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
81 stars 71 forks source link

Mock API fails with: TypeError: Cannot read property 'stop' of undefined #1323

Open orome opened 1 year ago

orome commented 1 year ago

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

v18.14.2

Amplify CLI Version

10.8.1

What operating system are you using?

macOS

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No manual changes made

Describe the bug

I get:

Failed to start API Mocking. Running cleanup tasks.
TypeError: Cannot read property 'stop' of undefined
    at APITest.stop (/snapshot/repo/build/node_modules/@aws-amplify/amplify-util-mock/lib/api/api.js:193:33)
    at APITest.start (/snapshot/repo/build/node_modules/@aws-amplify/amplify-util-mock/lib/api/api.js:156:18)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async start (/snapshot/repo/build/node_modules/@aws-amplify/amplify-util-mock/lib/api/index.js:18:5)
    at async Object.run (/snapshot/repo/build/node_modules/@aws-amplify/amplify-util-mock/lib/commands/mock/api.js:21:5)
    at async Object.executeAmplifyCommand (/snapshot/repo/build/node_modules/@aws-amplify/amplify-util-mock/lib/amplify-plugin-index.js:55:3)
    at async executePluginModuleCommand (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/execution-manager.js:144:5)
    at async executeCommand (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/execution-manager.js:42:9)
    at async Object.run (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/index.js:120:5)

Expected behavior

I expected the CLI to work

Reproduction steps

amplify mock api

Project Identifier

3863987f00fb7935a93679dd30c7e0f9

Log output

No response

Additional information

No response

Before submitting, please confirm:

josefaidt commented 1 year ago

Hey @orome :wave: thanks for raising this! This appears to be a duplicate of https://github.com/aws-amplify/amplify-category-api/issues/884, can you confirm whether your project has a GraphQL API?

orome commented 1 year ago

@josefaidt Yes, I have a GraphQL API and a REST API.

josefaidt commented 1 year ago

Hey @orome thanks for clarifying. Unfortunately I am only able to reproduce this when a GraphQL API is not present in the project, but I am taking a deeper look at this 🙂

josefaidt commented 1 year ago

Hey @orome can you try re-running the command with --debug and post the full output here?

orome commented 1 year ago

@josefaidt With --debug the output is exactly the same as in the OP.

josefaidt commented 1 year ago

Hey @orome thanks for checking. I have a few follow-up questions to better understand the context:

Additionally, we have a PR up to resolve this specific error, which should surface the actual error. Would you be open to verifying whether this prints a more helpful error?

gh repo clone aws-amplify/amplify-cli
gh pr checkout 12154
nvm use 14
yarn setup-dev
cd /your/project/directory
amplify-dev mock api
haukevb commented 1 year ago

I have the identical error. no resolver, no amplify/mock-data, java JRE 16 installed, just REST apis, no GraphQL apis. I did check with the PR as suggested by @josefaidt Here is my output:

Failed to start API Mocking. Running cleanup tasks. MockProcessFault: Failed to start API Mocking.. Reason: No AppSync API is added to the project at APITest.start (D:\DEV\dev2\projects\uNTT\amplify-cli\packages\amplify-util-mock\lib\api\api.js:103:19) at processTicksAndRejections (internal/process/task_queues.js:95:5) at async start (D:\DEV\dev2\projects\uNTT\amplify-cli\packages\amplify-util-mock\lib\api\index.js:11:9) at async Object.run (D:\DEV\dev2\projects\uNTT\amplify-cli\packages\amplify-util-mock\lib\commands\mock\api.js:14:9) at async Object.executeAmplifyCommand (D:\DEV\dev2\projects\uNTT\amplify-cli\packages\amplify-util-mock\lib\amplify-plugin-index.js:33:5) at async executePluginModuleCommand (D:\DEV\dev2\projects\uNTT\amplify-cli\packages\amplify-cli\lib\execution-manager.js:135:5) at async executeCommand (D:\DEV\dev2\projects\uNTT\amplify-cli\packages\amplify-cli\lib\execution-manager.js:33:9) at async Object.run (D:\DEV\dev2\projects\uNTT\amplify-cli\packages\amplify-cli\lib\index.js:117:5) { classification: 'FAULT', options: { message: 'Failed to start API Mocking.. Reason: No AppSync API is added to the project', link: 'https://docs.amplify.aws/cli/graphql/troubleshooting/' }, downstreamException: undefined, toObject: [Function (anonymous)], details: undefined, resolution: undefined, code: undefined, link: 'https://docs.amplify.aws/cli/graphql/troubleshooting/' }

Hope this helps.

bzwill commented 1 year ago

Also have this problem after calling amplify mock api:

TypeError: Cannot read property 'stop' of undefined at APITest.stop (/snapshot/repo/build/node_modules/@aws-amplify/amplify-util-mock/lib/api/api.js:193:33) at APITest.start (/snapshot/repo/build/node_modules/@aws-amplify/amplify-util-mock/lib/api/api.js:156:18) at processTicksAndRejections (internal/process/task_queues.js:95:5) at async start (/snapshot/repo/build/node_modules/@aws-amplify/amplify-util-mock/lib/api/index.js:18:5) at async Object.run (/snapshot/repo/build/node_modules/@aws-amplify/amplify-util-mock/lib/commands/mock/api.js:21:5) at async Object.executeAmplifyCommand (/snapshot/repo/build/node_modules/@aws-amplify/amplify-util-mock/lib/amplify-plugin-index.js:55:3) at async executePluginModuleCommand (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/execution-manager.js:135:5) at async executeCommand (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/execution-manager.js:33:9) at async Object.run (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/index.js:117:5)

New project with only 1 API endpoint