在VScode和Chrome中调试Vue,未绑定断点

问题描述 投票:0回答:5

我正在尝试调试我在 VSCode 和 Chrome 中编写的 Vue 网站。 当我在

data() { return {...} }
函数中放置断点时,它会停止,但如果我尝试将其放置在 Vue 文件或 JS 服务的方法中,一旦我通过调试配置启动 Chrome,断点就会解除绑定。有谁对如何保持断点绑定有任何想法? 这是我的配置文件:

"version": "0.2.0",
    "configurations": [
        {
            "name": "Launch Chrome",
            "request": "launch",
            "type": "pwa-chrome",
            "url": "http://localhost:8080",
            "webRoot": "${workspaceFolder}/client/meet-for-lunch/src",
            "sourceMapPathOverrides": {
              "webpack:///src/*": "${webRoot}/*"
            }
        },
        {
            "type": "node",
            "request": "launch",
            "name": "Debug server",
            "runtimeExecutable": "nodemon",
            "program": "${workspaceFolder}/server/bin/www",
            "restart": true,
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen",
            "skipFiles": [
                "<node_internals>/**"
            ]
        }

    ]
}

我包含了服务器的调试配置,因为它可以工作。

这是我尝试调试的方法的示例(来自 Vue 文件),我在

this.error = null
处放置了一个断点。该方法运行正常,所以我希望它在断点处停止:

        methods: {
            async login() {
                try {
                    this.error = null;
                    const response = await AuthenticationService.login({
                        email: this.email,
                        password: this.password
                    })
                    this.$store.dispatch('setToken', response.data.token)
                    this.$store.dispatch('setUser', response.data.user)

                }
                catch (err) {
                    console.log(`An error has occured: ${JSON.stringify(err.response)}`)
                    this.error = err.response.data.error
                }
            }
        } 

我也在尝试调试我的服务:

login(credentials) {
        return Api().post('/login', credentials)
    }

Api对象只是创建Axios请求

谢谢,

vue.js debugging visual-studio-code breakpoints
5个回答
18
投票

https://www.codegrepper.com/code-examples/javascript/vuejs+vscode+unbound+breakpoint

经过一整天的搜索解决了我的问题

{
"version": "0.2.0",  
"configurations": [  
  {
    "name": "WSL Chrome",
    "type": "chrome",
    "request": "launch",
    "url": "http://localhost:8080",
    "webRoot": "${workspaceFolder}/src",
    "sourceMapPathOverrides": {
        "webpack:///./src/*": "${webRoot}/*",
        "webpack:///src/*": "${webRoot}/*"
    }
  }
]

}


3
投票

当我在 VSCode 中有未绑定断点时,我最终需要使用

--inspect
--debug-brk=5858
标志来启动该过程。除此之外,
launch.json
给我带来了很多麻烦,而这些资源很有帮助

launch.json 示例:

    {
        "type": "node",
        "request": "attach",
        "name": "Node: Nodemon",
        "processId": "${command:PickProcess}",
        "restart": true,
        "protocol": "inspector",
    },
    {
        "name": "Launch tests via NPM",
        "type": "node",
        "request": "launch",
        "cwd": "${workspaceRoot}",
        "runtimeExecutable": "npm",
        "runtimeArgs": [
            "run-script", "testDebug"
        ],
        "port": 5858
    }

package.json

"scripts": {
  "start": "NODE_PATH=./src DEBUG=express:* NODE_ENV=dev nodemon -w src --ext ts --exec node --inspect -r tsconfig-paths/register -r ts-node/register src/index.ts",
  "testDebug": "NODE_ENV=test ts-mocha --debug-brk=5858 --paths -p tsconfig.json",
 }

1
投票

嗯,这并不是一个真正的答案,但我已经重新启动了我的 Node 服务器几次(更多)次,现在它停在了断点处。我希望问题不再出现。现在由于某种原因他没有显示变量的值,但我想这是另一个问题。

感谢您的帮助:)


0
投票

我的 vueJS 项目也遇到了同样的问题。在对文件等进行任何更改之前要尝试的东西为我解决了这个问题:

在 ClientApp/App 文件夹中: 1.删除 node_modules 文件夹 2.删除 package-lock.json 文件 3.打开 ClientApp/App 文件夹的 cmd 提示符 4.使用 cmd“npm i”

最后一步将重新安装所有节点模块。我遇到的问题一定是节点模块冲突。


0
投票

截至 2022 年 5 月...

请注意,如果您使用 vscodiumfirefox,您需要直接从市场安装 firefox-devtools:https://marketplace.visualstudio.com/items?itemName=firefox-devtools .vscode-firefox-调试

除此之外,

launch.json

 配置是标准的:

{ "name": "Vue:Client", "type": "firefox", "request": "launch", "url": "http://localhost:3000", "webRoot": "${workspaceFolder}/src", "pathMappings": [ { "url": "file://", "path": "" } ] },
扩展建议我插入这些路径映射。

参见

https://github.com/firefox-devtools/vscode-firefox-debug/issues/267

© www.soinside.com 2019 - 2024. All rights reserved.