LoginSignup
7
3

More than 5 years have passed since last update.

TypeScriptのコンパイル時に『error TS2304: Cannot find name 'Map'.』が出た時の対応

Posted at

TypeScriptコンパイル時にエラー

TypeScriptのコンパイル時、モジュールにbluebird(request-promiseなどの依存パッケージとしても使われている)を使っている場合、Mapが見つからないエラーとして、

$ tsc -p ./ts --outDir ./js

node_modules/@types/bluebird/index.d.ts:477:33 - error TS2304: Cannot find name 'Map'.

477   props<K, V>(this: PromiseLike<Map<K, Resolvable<V>>>): Bluebird<Map<K, V>>;

のようなエラーが出ることがあります。

対処法

tsconfig.jsonの"lib"の項目に、es6を追加してください。

{
  "compilerOptions": {
    /* Basic Options */
    "target": "es5",      /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
    "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
    // "lib": [],         /* Specify library files to be included in the compilation. */
    // "allowJs": true,   /* Allow javascript files to be compiled. */
    /* Basic Options */
    "target": "es5",      /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
    "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
    // "lib": ["es6"],         /* Specify library files to be included in the compilation. */
    // "allowJs": true,   /* Allow javascript files to be compiled. */

コンパイル時の参照ライブラリとしてES6がつかわれ、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