【发布时间】:2021-12-28 06:18:38
【问题描述】:
我正在学习 Next.js,并希望在可视化代码和 chrome 中进行调试。我尝试了不同的launch.json组合以在可视代码中调试next.js应用程序。我从堆栈溢出本身中获取其中一个代码。但它变成了另一个失败。 你能帮我如何使用谷歌浏览器在 Visual Studio 代码中调试 Next.js 应用程序吗?
下面是我的launch.json文件代码:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Example",
"runtimeExecutable": "node",
"runtimeArgs": ["--inspect", "node_modules/.bin/next", "dev"],
"port": 9229,
"cwd": "${workspaceFolder}/frontend",
"sourceMapPathOverrides": {
"webpack:///./*": "${workspaceRoot}/frontend/*"
}
}
]
}
我的 .next.config.js 代码
module.exports = {
webpack(config) {
config.devtool = 'cheap-module-eval-source-map'
return config
},
}
我的 package.json 用于前端
{
"name": "frontend",
"version": "1.0.0",
"description": "Social networking app",
"proxy": "http://127.0.0.1:8080",
"main": "index.js",
"scripts": {
"dev": "cross-env NODE_OPTIONS='--inspect' next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"author": "Vivek padelkar",
"license": "ISC",
"dependencies": {
"@ant-design/icons": "^4.7.0",
"antd": "^4.16.13",
"axios": "^0.24.0",
"bootstrap": "^5.1.3",
"next": "^12.0.3",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-toastify": "^8.1.0"
},
"devDependencies": {
"cross-env": "^7.0.3"
}
}
我的文件夹结构如下:
外部 pacakge.json 代码(即路径:SOCIAL NETWORK/pacakge.json”
{
"name": "socialnetwoek",
"version": "1.0.0",
"description": "social network backend",
"main": "server.js",
"type": "module",
"scripts": {
"start": "node backend/server",
"server": "nodemon backend/server",
"client": "npm run dev --prefix frontend",
"all": "concurrently \"npm run server\" \"npm run client\""
},
"author": "Vivek Padelkar",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"colors": "^1.4.0",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"esm": "^3.2.25",
"express": "^4.17.1",
"express-async-handler": "^1.2.0",
"joi": "^17.4.2",
"mongoose": "^6.0.12",
"morgan": "^1.10.0"
},
"devDependencies": {
"concurrently": "^6.4.0",
"nodemon": "^2.0.15"
}
}
我正在遵循的步骤:
- 在根文件夹(即社交网络)中,我正在执行命令
npm run all。 - 然后我按 F5 运行调试器。
下面是我的 vs 屏幕,我正在使用 Chrome 运行我的 Next.js 应用程序,所有调试点都显示为灰色。(用红色框突出显示)
但没有任何效果。
【问题讨论】:
标签: reactjs debugging visual-studio-code next.js vscode-debugger