gpt4 book ai didi

reactjs - 无法在 VS Code 中调试 React Typescript

转载 作者:行者123 更新时间:2023-12-03 15:56:55 33 4
gpt4 key购买 nike

我正在尝试在 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"
}
}

这是我的 tsconfig.json 文件
{
"compilerOptions": {
"target": "es6",
"jsx": "react",
"module": "commonjs"
},
"exclude": [
"node_modules"
]
}

这是我的 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;

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

最佳答案

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

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

react -v 16.8.6
节点 -v 10.16.0

{
"type": "chrome",
"request": "launch",
"name": "Debug React Run",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}/src"
}

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

关于reactjs - 无法在 VS Code 中调试 React Typescript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54369545/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com