简体   繁体   中英

Visual Studio Code won't stop at breakpoint in NativeScript app

I want to create a small android application using nativescript, but doing so without a debugger makes things much slower than they have to be. Since it's just a JS app, I decided to give a try to Visual Studio Code, which appears to work quite nicely with NativeScript apps at least in their tutorial videos, but when I try to use it, it doesn't seem to stop at any breakpoints. Here's my VSC launch configuration:

    {
        "name": "Launch on Android",
        "type": "nativescript",
        "request": "launch",
        "platform": "android",
        "appRoot": "${workspaceRoot}",
        "sourceMaps": true,
        "watch": true,
        "tnsArgs": "--emulator"
    }

I noticed that if I add "stopOnEntry": true to this configuration, the app actually stops at the very beginning like it should, but it looks like VSC's debugger doesn't really attach to the process, as the Play button remains disabled.

Here's my package.json

{
  "description": "NativeScript Application",
  "license": "SEE LICENSE IN <your-license-filename>",
  "readme": "NativeScript Application",
  "repository": "<fill-your-repository-here>",
  "scripts": {
    "recreate": "rm -rf platforms && rm -rf node_modules && npm install && tns platform add android"
  },
  "nativescript": {
    "id": "org.nativescript.forni",
    "tns-android": {
      "version": "2.5.1"
    }
  },
  "dependencies": {
    "lodash": "^4.17.4",
    "nativescript-oauth": "^1.2.1",
    "nativescript-telerik-ui": "^1.5.1",
    "tns-core-modules": "2.4.4"
  },
  "devDependencies": {
    "babel-traverse": "6.21.0",
    "babel-types": "6.21.0",
    "babylon": "6.15.0",
    "lazy": "1.0.11"
  }
}

and here's my app.js, which is where I hope to break:

const application = require("application");
application.start({ moduleName: "views/login/login" });

I'm using windows 10. I also tried running the app directly on my Samsung Galaxy S7, but it worked in exactly the same way.

On my Win10 machine, I had a similar issue. As it appeared, the debugger had been attached to late. You can check with adding a button that triggers function and set a breakpoint inside that function. It should work after hitting the button.

To resolve this issue, try to add --debug-brk option in tnsArgs inside launch.json file:

 {
      "name": "Launch on Android",
      "type": "nativescript",
      "request": "launch",
      "platform": "android",
      "appRoot": "${workspaceRoot}",
      "sourceMaps": true,
      "watch": true,
      "stopOnEntry": false,
      "tnsArgs": ["--debug-brk"]
    }

The docs: https://docs.nativescript.org/tooling/debugging/debugging

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM