Typescript + webpackのNodejsアプリでsource-mapを有効にする

公開日時
  • [[tsconfig.json]]のsourceMapを有効に
{
  "compilerOptions": {
    "sourceMap": true,
    // ...
  }
}
  • [[webpack.config.ts]]のdevtoolを設定
import * as Webpack from 'webpack';

const config: Webpack.Configuration = {
  devtool: 'inline-source-map',
  // ...
}
  • source-map-supportのインストール

Nodejsアプリの場合、上記の設定だけだとsource-mapが使えなかった。

evanw/node-source-map-supportを入れる必要があった。

yarn add source-map-support
  • rootとなる[[index.ts]]の先頭に以下を記述
import 'source-map-support/register';

これでエラー時にTypescriptコードの何行目でエラーが起きているか分かるようになった。


Related #js