Help us understand the problem. What is going on with this article?

Angularにgts導入したらaot buildできなくて詰んだ話

More than 1 year has passed since last update.

楽にLintを導入したかっただけなのに

$ npx gts init

何も考えずOverwriteポチー

エラーの山が襲来

AoT buildができない!

多すぎて一部抜粋。

これとか
addEventListener(element: HTMLElement, eventName: string, handler: Function): Function;

これとか
src/main.ts:12:17 - error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the `lib` compiler option to include 'dom'.

⇒ gtsでtsconfig.jsonが上書きしてしまったことが原因。

解決法

tsconfig.jsonのtargetやlibを戻せば解決した。

tsconfig.json
{
  "extends": "./node_modules/gts/tsconfig-google.json",
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "module": "esnext",
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ]
  },
  "include": [
    "src/**/*.ts",
    "test/**/*.ts"
  ],
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  }
}

momokura
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away