简体   繁体   English

Next.js 和 FireFox 使用源映射进行调试

[英]Next.js and FireFox debugging with source maps

I'm using Next.js, and have followed the recipe locatedhere modified by this open bug report to fix breakpoints in node.我正在使用 Next.js,并按照此公开错误报告修改的此处的配方来修复节点中的断点。

Breakpoints in Node are working great. Node 中的断点运行良好。 They are also kind of working in FireFox.他们也在 FireFox 中工作。 When I add a breakpoint inside my render, it will move to a different line and a pop-up will come up in VSCode which says:当我在渲染中添加断点时,它会移动到不同的行,并且 VSCode 中会出现一个弹出窗口,其中说:

This file's path isn't mapped to any url that was loaded by Firefox.此文件的路径未映射到 Firefox 加载的任何 url。 Perhaps your debug configuration needs a pathMapping for this file - do you want to let the Path Mapping Wizard try to create one for you?也许您的调试配置需要此文件的路径映射 - 您想让路径映射向导尝试为您创建一个吗?

Clicking yes does nothing.单击是什么都不做。 It will break at the appropriate point, but I'm trying to figure out how to get rid of this warning and stop the breakpoints from jumping.它会在适当的点中断,但我试图弄清楚如何摆脱这个警告并阻止断点跳跃。

launch.json启动文件

"configurations": [
    {
      "name": "Next: Launch",
      "type": "firefox",
      "request": "launch",
      "reAttach": true,
      "url": "http://localhost:3000",
      "webRoot": "${workspaceFolder}",
      "profile": "dev-edition-default"
    },
    {
      "type": "node",
      "request": "launch",
      "name": "Next: Node",
      "runtimeExecutable": "${workspaceFolder}/node_modules/next/dist/bin/next",
      "port": 9230,
      "console": "integratedTerminal",
      "env": {
        "NODE_OPTIONS": "--inspect=9230"
      }
    }],
  "compounds": [
    {
      "name": "Next: Full Launch",
      "configurations": ["Next: Node", "Next: Launch"]
    },
    {
      "name": "Next: Full Attach",
      "configurations": ["Next: Node", "Next: Attach"]
    }
  ]

next.config.js下一个.config.js

module.exports = {
  webpack(config) {
    config.devtool = "eval-source-map";
    return config;
  }
};

tsconfig.json配置文件

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "typeRoots": ["node_modules/mapkit-typescript", "node_modules/@types"],
    "sourceMap": true
  },
  "exclude": ["node_modules"],
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
}

Your launch.json file specifies "url": "http://localhost:3000" but I assume in Firefox you're opening localhost:9230.您的 launch.json 文件指定了"url": "http://localhost:3000"但我假设您在 Firefox 中打开的是 localhost:9230。 Change the launch.json URL to the correct port and the error should go away :)将 launch.json URL 更改为正确的端口,错误应该会消失:)

Edit:编辑:

Since the above was wrong, try this:由于上述错误,请尝试以下操作:

https://github.com/felixfbecker/vscode-php-debug/issues/254#issuecomment-410244336 https://github.com/felixfbecker/vscode-php-debug/issues/254#issuecomment-410244336

In your firefox object, add a pathMappings key and the value is an object that maps the local filepath to the localhost url.在您的 firefox 对象中,添加一个 pathMappings 键,该值是一个将本地文件路径映射到 localhost url 的对象。

{
  "name": "Next: Launch",
  "type": "firefox",
  "request": "launch",
  "reAttach": true,
  "url": "http://localhost:3000",
  "webRoot": "${workspaceFolder}",
  "profile": "dev-edition-default",
  "pathMappings": {
    "path/in/your/computer/index.html":"http://localhost:3000/index.html"
  }
},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM