Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug using NodeJS is resulting in vscode using "read only content from NodeJS" #26782

Closed
ajayp opened this issue May 17, 2017 · 7 comments
Closed
Assignees
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues

Comments

@ajayp
Copy link

ajayp commented May 17, 2017

  • VSCode Version: Code 1.12.2 (19222cd, 2017-05-10T13:13:11.413Z)
  • OS Version: Darwin x64 16.6.0
  • Extensions: none

Steps to Reproduce:

  1. Open up NodeJS project, file is in UTF-8
  2. Set Debug config as
    {
    "version": "0.2.0",
    "configurations": [
    {
    "name": "Debug Function",
    "type": "node",
    "request": "attach",
    "port": 5858
    }
    ]
    }
  3. Run debug
  4. Stop debug
  5. Make code change to index.js
  6. Restart debug to reproduce issue.
@Tyriar Tyriar added the debug Debug viewlet, configurations, breakpoints, adapter issues label May 17, 2017
@weinand weinand added the info-needed Issue requires more information from poster label May 17, 2017
@weinand
Copy link
Contributor

weinand commented May 17, 2017

@ajayp how do you start your node.js program?
Make sure that you run your program from the same directory as the VS Code workspace.

@ajayp
Copy link
Author

ajayp commented May 22, 2017

@weinand - Apologizes for the delay, was away for a bit but back niow,

I am using ngrok on my machine with the Google Functions Emulator https://github.com/GoogleCloudPlatform/cloud-functions-emulator/wiki/Debugging-with-Visual-Studio-Code

The emulator is running from the same directory as my codel

I am not sure if this answers your question fully, in future, I will be responding in a more timely manner.

@ajayp
Copy link
Author

ajayp commented May 23, 2017

@weinand - not sure how much this helps, the issue is not present in version 1.2.1 of vscode which is the version I rolled back to.

@aschrijver
Copy link

I can confirm this issue on VS Code 1.13.1. I think there is something wrong with the debug configuration, as the debugger is not running from the source maps it seems, but from what it finds in your project folder.

I have a React Native project with a bunch of Node shims, but when I run the debugger on my Jest unit tests the shims are not there, code is jumping to node internal objects (fs, etc.), not shims.

My configuration is:

        {
            "type": "node",
            "request": "launch",
            "name": "Launch Current TestSuite",
            "program": "${workspaceRoot}/node_modules/.bin/jest",
            "args": [
                "--runInBand",
                "--no-cache",
                "${file}"
            ],
            "runtimeArgs": [
                "--debug-brk=127.0.0.1:5858"
            ],
            "port": 5858,
            "sourceMaps": true
        }

@weinand
Copy link
Contributor

weinand commented Jul 13, 2017

What version of node are you using?

In general it should not be necessary to explicitly set the debug port. So these lines should be removed:

"runtimeArgs": [
   "--debug-brk=127.0.0.1:5858"
],
"port": 5858,

Instead if you want to control whether debug protocol is used, add a "protocol": "legacy" or "protocol": "inspector" attribute. With this the correct debug port and debug options are passed to node.

"sourceMaps": true is not needed because that's the default anyways. But you might want to specify the location of the generated code via the "outFiles" attribute, e.g. something like this:

  "outFiles": [
    "${workspaceRoot}/out/**/*.js"
  ]

@aschrijver
Copy link

aschrijver commented Jul 13, 2017

Thanks for your help! I had significant problems with node v8, so I downgraded to 7.10.1 and thought I had it working.

The details are in this stackoverflow post.

I removed the superfluous configuration, but it still gives the same results and my unit tests succeed, where they should in fact fail (there are fs.readFileSync calls coming through, while fs is mocked out).

        {
            "type": "node",
            "request": "launch",
            "name": "Launch Current TestSuite",
            "program": "${workspaceRoot}/node_modules/.bin/jest",
            "args": [
                "--runInBand",
                "--no-cache",
                "${file}"
            ],
            "outFiles": [
                "${workspaceRoot}/android/app/build/intermediates/assets/debug/*.bundle"
            ]
        }

Should I create a prelaunchTask to build the bundle and .map files in ${workspaceRoot}/.vscode/.react and then point to that in outFiles, or should I rollback as @ajayp suggests?

[UPDATE: I created an additional stackoverflow question for this: Debugging React Native with Node shims in VS Code]

@weinand
Copy link
Contributor

weinand commented Mar 2, 2018

Since this issue is rather old and both VS Code and node.js have evolved, I'm closing it.
If you still see the issue in recent version please create a new issue.

@weinand weinand closed this as completed Mar 2, 2018
@weinand weinand removed the info-needed Issue requires more information from poster label Mar 2, 2018
@vscodebot vscodebot bot locked and limited conversation to collaborators Apr 16, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues
Projects
None yet
Development

No branches or pull requests

4 participants