typescript - Čerstvá aplikácia Angular 9 s "CHYBA v Cannot read property 'flags' of undefined" na Mac pri "ng build"


Vytvoril som novú aplikáciu Angular 9 na svojom Macu pomocou

ng new demo (no routing, CSS)
cd demo
ng build

ktorý zlyhá pri

ERROR in Cannot read property 'flags' of undefined

"ng version" zobrazuje

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 9.0.5
Node: 12.16.1
OS: darwin x64

Angular: 9.0.5
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.900.5 (cli-only)
@angular-devkit/build-angular   0.900.5
@angular-devkit/core            9.0.5 (cli-only)
@angular-devkit/schematics      9.0.5 (cli-only)
@schematics/angular             9.0.5 (cli-only)
@schematics/update              0.900.5 (cli-only)
rxjs                            6.5.4
typescript                      3.7.5

Vypátral som to až ku

TypeError: Cannot read property 'flags' of undefined
    at checkUnreachable (/Users/im/tmp/demo/node_modules/typescript/lib/typescript.js:31915:31)
    at bindChildrenWorker (/Users/im/tmp/demo/node_modules/typescript/lib/typescript.js:29665:17)
    at bindChildren (/Users/im/tmp/demo/node_modules/typescript/lib/typescript.js:29621:17)
    at bind (/Users/im/tmp/demo/node_modules/typescript/lib/typescript.js:31056:21)
    at bindSourceFile (/Users/im/tmp/demo/node_modules/typescript/lib/typescript.js:29211:17)
    at Object.bindSourceFile (/Users/im/tmp/demo/node_modules/typescript/lib/typescript.js:29148:9)
    at initializeTypeChecker (/Users/im/tmp/demo/node_modules/typescript/lib/typescript.js:64532:20)
    at Object.createTypeChecker (/Users/im/tmp/demo/node_modules/typescript/lib/typescript.js:33768:9)
    at Object.getTypeChecker (/Users/im/tmp/demo/node_modules/typescript/lib/typescript.js:95767:79)
    at NgCompiler.makeCompilation (/Users/im/tmp/demo/node_modules/@angular/compiler-cli/src/ngtsc/core/src/compiler.js:542:42)
    at NgCompiler.<anonymous> (/Users/im/tmp/demo/node_modules/@angular/compiler-cli/src/ngtsc/core/src/compiler.js:191:53)
    at step (/Users/im/tmp/demo/node_modules/tslib/tslib.js:139:27)
    at Object.next (/Users/im/tmp/demo/node_modules/tslib/tslib.js:120:57)
    at /Users/im/tmp/demo/node_modules/tslib/tslib.js:113:75
    at new Promise (<anonymous>)
    at Object.__awaiter (/Users/im/tmp/demo/node_modules/tslib/tslib.js:109:16)

Čo sa zdá, že sa stane počas spracovania súboru: /Users/im/tmp/demo/node_modules/@angular-devkit/build-angular/node_modules/typescript/lib/lib.es5.d.ts

Máte nejakú predstavu, čo sa tu pokazilo?

Niektoré informácie o verzii mimo pracovného priestoru

npm version

{
  demo: '0.0.0',
  npm: '6.14.2',
  ares: '1.15.0',
  brotli: '1.0.7',
  cldr: '35.1',
  http_parser: '2.9.3',
  icu: '64.2',
  llhttp: '2.0.4',
  modules: '72',
  napi: '5',
  nghttp2: '1.40.0',
  node: '12.16.1',
  openssl: '1.1.1d',
  tz: '2019c',
  unicode: '12.1',
  uv: '1.34.0',
  v8: '7.8.279.23-node.31',
  zlib: '1.2.11'
}

ng version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 9.0.5
Node: 12.16.1
OS: darwin x64

Angular: 
... 
Ivy Workspace: 

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.900.5
@angular-devkit/core         9.0.5
@angular-devkit/schematics   9.0.5
@schematics/angular          9.0.5
@schematics/update           0.900.5
rxjs                         6.5.3

node -v
v12.16.1

Odpoveď č. 1

Našiel som nasledujúce riešenie:

Po ng new demo som skontroloval súbor package-lock.json a všimol som si, že @angular-devkit/build-angular a @angular-devkit/build-optimizer používajú verziu 3.6.4 typescriptu.

Po opravení súboru package-lock.json a spustení npm install, aby tiež používali verzia TypeScript 3.7.5, ako samotná aplikácia, to začalo fungovať.

Ďalším riešením je prechod na yarn, čo tiež okamžite vyriešilo tento problém:

ng new demo --packageManager=yarn

Súvisiace články