VSCodeでNext.jsのプロジェクトをデバッグ中、下記のエラーが出ます。
Could not read source map
ENOENT: no such file or directory
これを解決するには .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 は出なくなりましたので、そういうことのようです。