amplify-cli: Error when running Amplify 8.x from VSCode debugger
Before opening, please confirm:
- I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
- I have searched for duplicate or closed issues.
- I have read the guide for submitting bug reports.
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
- I have removed any sensitive information from my code snippets and submission.
How did you install the Amplify CLI?
npm
If applicable, what version of Node.js are you using?
v16.14.0
Amplify CLI Version
8.0.2
What operating system are you using?
Mac
Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
Didn’t get there yet
Amplify Categories
Not applicable
Amplify Commands
configure
Describe the bug
I just installed the cli with: npm i -g @aws-amplify/cli from VSCode terminal.
It was not working and I also tried to downgrade from 8.0.2 to 8.0.0: npm install -g @aws-amplify/cli@8.0.0
With both times it would throw the same error when running any amplify command:
internal/modules/package_json_reader.js:4 const internalModuleReadJSON = function (f) { return require(‘fs’).internalModuleReadJSON(f); }; ^
TypeError: require(…).internalModuleReadJSON is not a function at internalModuleReadJSON (internal/modules/package_json_reader.js:4:68) at Object.read (internal/modules/package_json_reader.js:21:34) at readPackage (internal/modules/cjs/loader.js:264:36) at readPackageScope (internal/modules/cjs/loader.js:297:19) at trySelf (internal/modules/cjs/loader.js:412:40) at Function.Module._resolveFilename (internal/modules/cjs/loader.js:879:24) at Function.Module._load (internal/modules/cjs/loader.js:746:27) at Module.require (internal/modules/cjs/loader.js:974:19) at Module._preloadModules (internal/modules/cjs/loader.js:1244:12) at loadPreloadModules (internal/bootstrap/pre_execution.js:480:5)
When I run amplify from the Mac terminal it works. It’s weird because sam and aws work just fine from both terminals.
Expected behavior
to work
Reproduction steps
- npm install -g @aws-amplify/cli@8.0.0
- amplify configure
GraphQL schema(s)
# Put schemas below this line
Log output
# Put your logs below this line
Additional information
No response
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 1
- Comments: 33 (11 by maintainers)
Commits related to this issue
- fix: prevent `NODE_OPTIONS` from affecting pkg binary (#10284) — committed to jonscheiding/amplify-cli by jonscheiding a year ago
- fix: update to latest version of `pkg` (#10284) Fixes an issue where having a `NODE_OPTIONS` var set in your environment causes Amplify to puke — committed to jonscheiding/amplify-cli by jonscheiding a year ago
- fix: update to latest version of `pkg` (#10284) Fixes an issue where having a `NODE_OPTIONS` var set in your environment causes Amplify to puke — committed to jonscheiding/amplify-cli by jonscheiding a year ago
- fix: update to latest version of `pkg` (#10284) Fixes an issue where having a `NODE_OPTIONS` var set in your environment causes Amplify to puke — committed to jonscheiding/amplify-cli by jonscheiding a year ago
- fix: update to latest version of `pkg` (#10284) (#11796) Fixes an issue where having a `NODE_OPTIONS` var set in your environment causes Amplify to puke — committed to aws-amplify/amplify-cli by jonscheiding a year ago
Disable JavaScript Debugger Companion Disable JavaScript Debugger Enable them again Kill terminal It works
This works for me: Turning off the built-in debugging support for vscode which is shown around the bottom left of the vscode window as described below will solve the issue: https://code.visualstudio.com/docs/nodejs/nodejs-debugging
When you need to debug JS, just set it again - this is an issue only when running Amplify commands.
Yes. This worked for me. Thank you!
From: Pavlo Huk @.> Sent: Sunday, June 19, 2022 9:14 AM To: aws-amplify/amplify-cli @.> Cc: sankranti2018 @.>; Comment @.> Subject: Re: [aws-amplify/amplify-cli] Error when running Amplify 8.x from VSCode debugger (Issue #10284)
Disable JavaScript Debugger Companion Ext Disable JavaScript Debugger Enable them again Kill terminal It works
— Reply to this email directly, view it on GitHubhttps://github.com/aws-amplify/amplify-cli/issues/10284#issuecomment-1159663745, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABMQT3JCNSJ7F43LUELSHVDVP3QHXANCNFSM5UIGX6AA. You are receiving this because you commented.Message ID: @.***>
Hey @two-pack thank you for clarifying that piece! I was not trying to reproduce with the VSCode debugger initially but now I am seeing both issues you have noticed:
Given this issue started to occur with 8.x and has broken existing workflows I will mark this as a bug for the team to evaluate further 🙂
I had the same problem since 8.0.0.
I was able to fix it by uninstalling the Extension “Debugger for Chrome”. I also disabled and then re-enabled the “Javascript Debugger” and the “JavaScript Debugger Companion Extension”, but I’m not sure if this was needed.
After deleting the Build-In Terminal and opening a new one I could finally run
amplify -vwithout this errorI reproduced same error with the following command in WSL Bash and VSCode’ integrated terminal. NOTE: debugfunc is a name of amplify function (Lambda).
Above command is for debugging of amplify functions with following setting. But some environment options are removed because rejected other errors.
The original command is following.
I success the command If I removed NODE_OPTIONS --require. And I alse success with simple js code (which only console.log) instead of amplify.
So I think this issue is caused a combination of amplify and VSCode JavaScript Debugger in my case. And it is probably different from the original issue case.
VSCode versions are
And the version of JavaScript Debugger extension is v1.67.2.
It’s ok if I’m free, but my english is poor especially speaking and listening.