7
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Next.jsをVSCodeでデバッグ中に出る Could not read source map の解決法

Last updated at Posted at 2023-06-30

VSCodeでNext.jsのプロジェクトをデバッグ中、下記のエラーが出ます。

Could not read source map 
ENOENT: no such file or directory

スクリーンショット 2023-06-30 102759.png

これを解決するには .vscode/launch.json の設定を以下(変更前 → 変更後)のように設定します。

launch.json(変更前)
{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "chrome",
      "request": "launch",
      "name": "Next.js Client",
      "url": "http://localhost:3000",
      "webRoot": "${workspaceFolder}",
    }
  ]
}
launch.json(変更後)
{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "chrome",
      "request": "launch",
      "name": "Next.js Client",
      "url": "http://localhost:3000",
      "webRoot": "${workspaceFolder}",
      "resolveSourceMapLocations": [
        "${workspaceFolder}/**",
        "!**/node_modules/**"
      ]
    }
  ]
}
      "resolveSourceMapLocations": [
        "${workspaceFolder}/**",
        "!**/node_modules/**"
      ]

によって明示的にSourcemapを探しに行く範囲を定義しているようですね。
"!**/node_modules/**"でnode_modulesディレクトリを探す範囲から除外しているのが良いのだろうかと思って

      "resolveSourceMapLocations": [
        "!**/node_modules/**"
      ]

と書き直してlaunchすると、やはり Could not read source map は出なくなりましたので、そういうことのようです。

7
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?