Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fresh Angular 9 app with "ERROR in Cannot read property 'flags' of undefined" on Mac on "ng build"

I created a new Angular 9 application on my Mac using

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

which fails with

ERROR in Cannot read property 'flags' of undefined

"ng version" shows

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


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

I tracked it down to

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)

Which seems to happen while processing the file: /Users/im/tmp/demo/node_modules/@angular-devkit/build-angular/node_modules/typescript/lib/lib.es5.d.ts

Any idea what is going wrong here?

Some version info from outside the workspace

# 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

like image 280
Mario Avatar asked Mar 06 '20 16:03

Mario


1 Answers

I found the following solution:

After ng new demo I checked the package-lock.json file and noticed that @angular-devkit/build-angular and @angular-devkit/build-optimizer are using version 3.6.4 of typescript.

After patching package-lock.json file and npm install so they are also using typescript version 3.7.5 as the app itself does it started to work.

Another solution is switching to yarn which also fixed that issue right from the start:

ng new demo --packageManager=yarn
like image 137
Mario Avatar answered Nov 05 '22 03:11

Mario