无法在 VS Code 中调试 React Typescript

wol*_*928 5 debugging typescript reactjs

我正在尝试在 VS Code 中调试 React Typescript 应用程序,但我不知道如何配置 launch.json 以使 TSX 调试工作。

我正在使用 webpack 将所有内容捆绑到一个 js 文件中

这是我的 package.json

 {
  "name": "reactts",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "magic": "webpack"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@types/react": "^16.7.20",
    "@types/react-dom": "^16.0.11",
    "axios": "^0.18.0",
    "react": "^16.7.0",
    "react-dom": "^16.7.0",
    "ts-loader": "^5.3.3",
    "typescript": "^3.2.4"
  }
}
Run Code Online (Sandbox Code Playgroud)

这是我的 tsconfig.json 文件

{
    "compilerOptions": {
      "target": "es6",
      "jsx": "react",
      "module": "commonjs"
    },
    "exclude": [
      "node_modules"
    ]
}
Run Code Online (Sandbox Code Playgroud)

这是我的 webpack.config.js 文件

var path = require("path");
var config = {
  entry: ["./src/app.tsx"],
  output: {
    path: path.resolve(__dirname, "build"),
    filename: "bundle.js"
  },
  resolve: {
    extensions: [".ts", ".tsx", ".js"]
  },

  module: {
    rules: [
      {
        test: /\.tsx?$/,
        loader: "ts-loader",
        exclude: /node_modules/
      }
    ]
  }
};

module.exports = config;
Run Code Online (Sandbox Code Playgroud)

我使用 npm run magic 将 tsx 代码编译成捆绑的 js 文件

xIs*_*sra 8

没有使用 webpack而是只使用react create-app ( npm start= react-scripts start)提供的脚本,然后我Chrome Debugger使用 VS Code 调试配置启动:

直接指向 app.tsx 和 index.ts 所在应用的源/src。

反应 -v 16.8.6 节点 -v 10.16.0

{
    "type": "chrome",
    "request": "launch",
    "name": "Debug React Run",
    "url": "http://localhost:3000",
    "webRoot": "${workspaceFolder}/src"
}
Run Code Online (Sandbox Code Playgroud)

如果我找到 webpack 的解决方案,我会更新。