typescript - NextJS VSCode Typescript ==> 断点未绑定
问题描述
我遵循本文档中的 Next.js 说明:https ://nextjs.org/docs/advanced-features/debugging#using-the-debugger-in-visual-studio-code
尝试调试我的 Next.js 项目。该过程开始,调试器正确附加并显示来自调试的日志消息。但是,当我设置断点时,它仍然会褪色,当我将其悬停时,VSCode 会显示“未绑定断点”。更不用说,调试器不会在断点处停止。
但是,如果我使用关键字“调试器”,那么调试器确实会停在我使用它的地方。
我的系统:
"next": "9.4.4",
tsconfig.json:
{
"compilerOptions": {
"downlevelIteration": true,
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"sourceMap": true,
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"allowUnreachableCode": false,
"jsx": "preserve",
"baseUrl": ".",
"paths": {
"types/": [
"src/types/index"
],
"types/*": [
"src/types/*",
"src/types/index"
],
"data/*": [
"src/data/*"
],
},
},
"exclude": [
"node_modules"
],
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"next.config.js"
],
"compileOnSave": true
}
解决方案
我遇到了 TypeScript + React 的断点未绑定问题。这是我的launch.json,我添加了这些属性并让它工作:
"sourceMaps": true,
"breakOnLoad": true,
"sourceMapPathOverrides": {
"webpack:///./src/*": "${webRoot}/dist/*",
"webpack:///src/*": "${webRoot}/dist/*"
}
}
完整的launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Debug React Run",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}/src",
"sourceMaps": true,
"breakOnLoad": true,
"sourceMapPathOverrides": {
"webpack:///./src/*": "${webRoot}/dist/*",
"webpack:///src/*": "${webRoot}/dist/*"
}
}
]
}
推荐阅读
- java - 当firebase实时数据库中没有数据时,为什么progressDialog不会被关闭?
- python - 如何在bs4中获取表格的动态高度和宽度
- azure-blob-storage - Azure Blob - 在不知道容器名称的情况下获取 Blob 列表
- html - CSS自定义组合框问题
- python - Pytorch:为什么 print(model) 不显示激活函数?
- swift - 如何自定义推送通知?
- python - 按数据框分组,条件是两个字符串之间的相似性度量
- c - 头变量归零
- powerbi - 我的 Power BI 查询(使用参数)有什么问题?
- javascript - stoppropagation 在 Angular 8 中没有按预期工作