【问题标题】:"Could not read source map" errors when connecting to Node debugger (Next.js)连接到 Node 调试器 (Next.js) 时出现“无法读取源映射”错误
【发布时间】:2021-03-22 01:26:37
【问题描述】:

我正在关注Next.js debugging docs 设置我的本地调试环境。

“第 1 步:在调试模式下启动 Next.js”工作正常:

> cross-env NODE_OPTIONS='--inspect' next dev

Debugger listening on ws://127.0.0.1:9229/e4bb955d-e3b2-4849-b6e7-0248e6a3d53e
For help, see: https://nodejs.org/en/docs/inspector
Loaded env from C:\Users\markj\workspace\my-app\.env.local
ready - started server on http://localhost:3000
info  - Using external babel configuration from C:\Users\markj\workspace\my-app\babel.config.js
event - compiled successfully

但是在“第 2 步:连接到调试器”中,我在 VSCode 调试控制台中收到这些错误:

Could not read source map for file:///C:/Users/markj/workspace/my-app/node_modules/next/dist/compiled/path-to-regexp/index.js: ENOENT: no such file or directory, open 'c:\Users\markj\workspace\my-app\node_modules\next\dist\compiled\path-to-regexp\index.js.map'
Could not read source map for file:///C:/Users/markj/workspace/my-app/node_modules/@next/react-refresh-utils/ReactRefreshWebpackPlugin.js: ENOENT: no such file or directory, open 'c:\Users\markj\workspace\my-app\node_modules\@next\react-refresh-utils\ReactRefreshWebpackPlugin.js.map'
Could not read source map for file:///C:/Users/markj/workspace/my-app/node_modules/typescript/lib/typescript.js: ENOENT: no such file or directory, open 'c:\Users\markj\workspace\my-app\node_modules\typescript\lib\typescript.js.map'
Could not read source map for file:///C:/Users/markj/workspace/my-app/node_modules/@next/react-refresh-utils/loader.js: ENOENT: no such file or directory, open 'c:\Users\markj\workspace\my-app\node_modules\@next\react-refresh-utils\loader.js.map'
Could not read source map for file:///C:/Users/markj/workspace/my-app/node_modules/@next/react-refresh-utils/internal/ReactRefreshModule.runtime.js: ENOENT: no such file or directory, open 'c:\Users\markj\workspace\my-app\node_modules\@next\react-refresh-utils\internal\ReactRefreshModule.runtime.js.map'

不出所料,当我尝试附加断点时出现这些错误,它显示“未绑定断点”。

环境:

  • Windows 10.0.19042
  • Node.js 12.20.0
  • Next.js 10.0.2
  • VSCode 1.51.1

非常感谢任何帮助或想法!

【问题讨论】:

    标签: node.js debugging visual-studio-code next.js


    【解决方案1】:

    这本质上是由它不应该尝试调试的 VSCode 调试文件引起的,即 node_modules。在这方面有一些 github 问题,herehere。我觉得很有用。本质上,解决方法是阻止 VSCode 关心这些文件,您可以通过设置 "type":"pwa-node" 并添加:

    "resolveSourceMapLocations": [
        "${workspaceFolder}/",
        "!/node_modules/**"
    ],
    

    .vscode下的launch.json

    【讨论】:

      猜你喜欢
      • 2014-12-19
      • 1970-01-01
      • 2013-05-02
      • 2019-01-29
      • 2020-11-02
      • 2013-07-15
      • 2020-05-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多