我尝试使用VS Code Chrome调试器调试Angular2(2.0.0-beta.9)&打字稿(v1.8.7)。我在ts文件中设置了断点,但是调试器正在显示js。当整个应用程序位于一个文件夹中时,调试器会显示ts,但当应用程序由子文件夹组成时,它不会正常运行。起初我以为它无法解决映射,但是我已经打开了诊断程序并且可以看到路径正在被正确解析。
以下是诊断窗口中的示例:
›Paths.scriptParsed: resolved http://localhost:3000/bin/hero/hero.service.js to c:\MyDev\ng2\bin\hero\hero.service.js. webRoot: c:\MyDev\ng2
›SourceMaps.createSourceMap: Reading local sourcemap file from c:\MyDev\ng2\bin\hero\hero.service.js.map
›SourceMap: creating SM for c:\MyDev\ng2\bin\app.component.js
›SourceMap: no sourceRoot specified, using script dirname: c:\MyDev\ng2\bin
›SourceMaps.scriptParsed: c:\MyDev\ng2\bin\app.component.js was just loaded and has mapped sources: ["c:\\MyDev\\ng2\\app\\app.component.ts"]
›SourceMaps.scriptParsed: Resolving pending breakpoints for c:\MyDev\ng2\app\app.component.ts
tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"outDir": "bin"
},
"exclude": [
"node_modules",
"typings"
]
}
launch.json的部分:
{
"name": "Launch localhost with sourcemaps",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000/index.html",
"sourceMaps": true,
"webRoot": "${workspaceRoot}",
"diagnosticLogging": true
}
答案 0 :(得分:0)
不幸的是,源代码到Webpack文件的正确映射已经改变了几次。
您已在diagnosticLogging
中启用launch.json
,这意味着您应该在JavaScript控制台中添加以下内容:
SourceMap: mapping webpack:///./src/main.ts => C:\Whatever\The\Path\main.ts
这可以让您清楚地了解它在哪里搜索您的源代码。
然后,您向sourceMapPathOverrides
添加launch.json
条目,以帮助其找到您的文件。看起来应该是这样的:
"sourceMapPathOverrides": {
"webpack:///./*": "${workspaceRoot}/SourceFolder/*"
},
显然,将SourceFolder替换为实际路径。