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

  1. npm install -g @aws-amplify/cli@8.0.0
  2. 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

Most upvoted comments

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:

  • typical debug launch.json throws NODE_OPTIONS issue
    /Users/josef/.amplify/bin/amplify: --inspect-publish-uid= is not allowed in NODE_OPTIONS
    
  • copying the command that the debugger outputted to the terminal and removing the option noted in the error above we encounter the error originally described here
{
  "configurations": [
    {
      "name": "Mock Amplify function",
      "request": "launch",
      "type": "node",
      "runtimeExecutable": "amplify",
      "runtimeArgs": [
        "mock",
        "function",
        "myfunction",
        "--event",
        "src/event.json"
      ],
      "console": "integratedTerminal"
    }
  ]
}

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 -v without this error

I reproduced same error with the following command in WSL Bash and VSCode’ integrated terminal. NOTE: debugfunc is a name of amplify function (Lambda).

$ /usr/bin/env 'NODE_OPTIONS=--require /home/foo/.vscode-server/bin/da15b6fd3ef856477bf6f4fb29ba1b7af717770d/extensions/ms-vscode.js-debug/src/bootloader.bundle.js' /usr/bin/node ./../../../../usr/bin/amplify mock function debugfunc --event ts-src/event.json --timeout 0 
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)

Above command is for debugging of amplify functions with following setting. But some environment options are removed because rejected other errors.

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "debugfunc",
      "program": "/usr/bin/amplify",      
      "preLaunchTask":"webpack",
      "args": [
        "mock",
        "function",
        "debugfunc",
        "--event",
        "ts-src/event.json",
        "--timeout",
        "0"
      ],
      "console": "integratedTerminal",
      "sourceMaps": true,
      "smartStep": true,
      "outFiles": ["${workspaceFolder}/amplify/backend/function/debugfunc/src/**/*.js"],
      "sourceMapPathOverrides": {
        "webpack:///./*": "${workspaceFolder}/amplify/backend/function/debugfunc/*"
      }
    },
  ]
}

The original command is following.

$  cd /home/foo/dev/test-debug-func ; /usr/bin/env 'NODE_OPTIONS=--require /home/foo/.vscode-server/bin/da15b6fd3ef856477bf6f4fb29ba1b7af717770d/extensions/ms-vscode.js-debug/src/bootloader.bundle.js --inspect-publish-uid=http' 'VSCODE_INSPECTOR_OPTIONS={"inspectorIpc":"/tmp/node-cdp.850-3.sock","deferredMode":false,"waitForDebugger":"","execPath":"/usr/bin/node","onlyEntrypoint":false,"autoAttachMode":"always","mandatePortTracking":true,"fileCallback":"/tmp/node-debug-callback-4771749cf913d1dd"}' /usr/bin/node ./../../../../usr/bin/amplify mock function debugfunc --event ts-src/event.json --timeout 0 
Debugger attached.
/home/foo/.amplify/bin/amplify: --inspect-publish-uid= is not allowed in NODE_OPTIONS
Waiting for the debugger to disconnect...

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.

$ /usr/bin/env /usr/bin/node ./../../../../usr/bin/amplify mock function debugfunc --event ts-src/event.json --timeout 0
Ensuring latest function changes are built...
Starting execution...
<snip>
Finished execution.
$ echo 'console.log("test");' > test.js
$ /usr/bin/env 'NODE_OPTIONS=--require /home/foo/.vscode-server/bin/da15b6fd3ef856477bf6f4fb29ba1b7af717770d/extensions/ms-vscode.js-debug/src/bootloader.bundle.js' /usr/bin/node test.js
test

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

Version: 1.67.1 (system setup)
Commit: da15b6fd3ef856477bf6f4fb29ba1b7af717770d
Date: 2022-05-06T12:37:03.389Z
Electron: 17.4.1
Chromium: 98.0.4758.141
Node.js: 16.13.0
V8: 9.8.177.13-electron.0
OS: Windows_NT x64 10.0.22000

And the version of JavaScript Debugger extension is v1.67.2.

Would you be open to hopping on a quick call?

It’s ok if I’m free, but my english is poor especially speaking and listening.