【问题标题】:ERROR in TypeError: Cannot read property 'flags' of undefinedTypeError 中的错误:无法读取未定义的属性“标志”
【发布时间】:2020-08-23 12:31:46
【问题描述】:

当我尝试在最近创建的 Angular 项目上运行 ng serve 时遇到问题。 我使用的版本是 9.1.4,这个错误不会出现在 Angular 版本较旧的项目上。

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.901.4
@angular-devkit/build-angular     0.901.4
@angular-devkit/build-optimizer   0.901.4
@angular-devkit/build-webpack     0.901.4
@angular-devkit/core              9.1.4
@angular-devkit/schematics        9.1.4
@angular/cli                      9.1.4
@ngtools/webpack                  9.1.4
@schematics/angular               9.1.4
@schematics/update                0.901.4
rxjs                              6.5.5
typescript                        3.8.3
webpack                           4.42.0

执行ng serveng build后:

chunk {main} main.js, main.js.map (main) 2 kB [initial] [rendered]<br>
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 679 bytes [initial] [rendered]<br>
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]<br>
chunk {styles} styles.js, styles.js.map (styles) 12.4 kB [initial] [rendered]<br>
chunk {vendor} vendor.js, vendor.js.map (vendor) 339 kB [initial] [rendered]<br>
Date: 2020-05-08T02:06:46.145Z - Hash: 1a1b937f0ca2bb37634b - Time: 4087ms<br>

**ERROR in TypeError: Cannot read property 'flags' of undefined**
    at resolveAlias (C:\Cursos\Angular\ang-hello-world\node_modules\typescript\lib\typescript.js:36513:37)
    at checkAliasSymbol (C:\Cursos\Angular\ang-hello-world\node_modules\typescript\lib\typescript.js:64502:26)
    at checkImportBinding (C:\Cursos\Angular\ang-hello-world\node_modules\typescript\lib\typescript.js:64534:13)
    at checkImportDeclaration (C:\Cursos\Angular\ang-hello-world\node_modules\typescript\lib\typescript.js:64552:29)
    at checkSourceElementWorker (C:\Cursos\Angular\ang-hello-world\node_modules\typescript\lib\typescript.js:64961:28)
    at checkSourceElement (C:\Cursos\Angular\ang-hello-world\node_modules\typescript\lib\typescript.js:64800:17)
    at Object.forEach (C:\Cursos\Angular\ang-hello-world\node_modules\typescript\lib\typescript.js:317:30)
    at checkSourceFileWorker (C:\Cursos\Angular\ang-hello-world\node_modules\typescript\lib\typescript.js:65123:20)
    at checkSourceFile (C:\Cursos\Angular\ang-hello-world\node_modules\typescript\lib\typescript.js:65091:13)
    at getDiagnosticsWorker (C:\Cursos\Angular\ang-hello-world\node_modules\typescript\lib\typescript.js:65179:17)
    at Object.getDiagnostics (C:\Cursos\Angular\ang-hello-world\node_modules\typescript\lib\typescript.js:65165:24)
    at C:\Cursos\Angular\ang-hello-world\node_modules\typescript\lib\typescript.js:98703:85
    at runWithCancellationToken (C:\Cursos\Angular\ang-hello-world\node_modules\typescript\lib\typescript.js:98665:24)
    at getBindAndCheckDiagnosticsForFileNoCache (C:\Cursos\Angular\ang-hello-world\node_modules\typescript\lib\typescript.js:98691:20)
    at getAndCacheDiagnostics (C:\Cursos\Angular\ang-hello-world\node_modules\typescript\lib\typescript.js:98956:26)
    at getBindAndCheckDiagnosticsForFile (C:\Cursos\Angular\ang-hello-world\node_modules\typescript\lib\typescript.js:98688:20)

** **Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/** **

运行这个项目后我在浏览器上得到的结果是:

Cannot GET /

【问题讨论】:

  • 在 Angular 11 中仍然得到这个。

标签: angular typescript


【解决方案1】:

从 10.1.0 更新到 11.1.1 时遇到同样的问题。

将 TypeScript 从 4.0.2 更新到 4.1.3 的最新版本解决了这个问题:

npm i typescript@latest

【讨论】:

  • 谢谢!有同样的问题,解决了。
【解决方案2】:

试试这个解决方案:

npm install @angular/core@9.1.4 @angular/animations@9.1.4 @angular/common@9.1.4 @angular/forms@9.1.4 @angular/platform-browser@9.1.4 @angular/router@9.1.4 @angular/platform-browser-dynamic@9.1.4 @angular/compiler@9.1.4 @angular/compiler-cli@9.1.4 @angular/language-service@9.1.4

npm install

ng serve

【讨论】:

    【解决方案3】:

    编辑

    如果你使用 Angular 9.1.6 现在应该没问题

    npm update @angular/cli @angular/core
    

    原帖

    Angular 9.1.5 中有些问题 - 如果您运行以下命令,它应该可以工作:

    npm install @angular/core@9.1.4 @angular/animations@9.1.4 @angular/common@9.1.4 @angular/forms@9.1.4 @angular/platform-browser@9.1.4 @angular/router@9.1.4 @angular/platform-browser-dynamic@9.1.4 @angular/compiler@9.1.4 @angular/compiler-cli@9.1.4 @angular/language-service@9.1.4
    
    ng build
    

    只花了大约 4-5 个小时试图自己修复它......

    问题似乎源于使用 Angular CLI 9.1.4 和 Angular 9.1.5(很可能是编译器

    当你这样做时你会看到问题

    ng --version
    

    如果你得到:

    Angular CLI: 9.1.4
    Node: 12.16.3
    OS: win32 x64
    
    Angular: 9.1.5
    ... animations, cli, common, compiler, compiler-cli, core, forms
    ... language-service, platform-browser, platform-browser-dynamic
    ... router
    Ivy Workspace: Yes
    

    然后你需要按照我上面列出的 npm 安装进行操作

    【讨论】:

    • 谢谢也有效。我可以确认,这个问题正是在我从 9.1.4 升级到 9.1.5 时出现的。
    • 它也对我有用。谢谢。 9.1.5 @angular/cli 在 npm 上不再可用。
    • @Matt 你能告诉我你用的是哪个版本的节点吗?
    • @KiranRacherla 我正在使用节点 v12.16.3'
    • 在 package.json 文件中,我刚刚在所有带有“~9.1.4”的包之前删除了“~”。和 @angular/animations 的调整版本(以前使用“~9.1.5”)如下:“@angular/animations”:“9.1.4”。我正在使用最新版本的 nodeJS(这不是问题的根源):$ nvm list * 14.2.0(当前使用 64 位可执行文件)
    【解决方案4】:

    9.1.6 刚刚发布,应该可以解决这个问题

    【讨论】:

      【解决方案5】:

      @Matt 的回答也适用于 ng serve,但需要额外的步骤。 首先执行以下步骤“引用他的回答中的步骤”:

      1. 首先检查ng --version。如果得到,请转到下一步:
      Angular CLI: 9.1.4
      Node: 12.16.3
      OS: win32 x64
      
      Angular: 9.1.5
      ... animations, cli, common, compiler, compiler-cli, core, forms
      ... language-service, platform-browser, platform-browser-dynamic
      ... router
      Ivy Workspace: Yes
      
      1. 使用 9.1.4 作为版本强制重新安装 Angular 包:
      npm install @angular/core@9.1.4 @angular/animations@9.1.4 @angular/common@9.1.4 @angular/forms@9.1.4 @angular/platform-browser@9.1.4 @angular/router@9.1.4 @angular/platform-browser-dynamic@9.1.4 @angular/compiler@9.1.4 @angular/compiler-cli@9.1.4 @angular/language-service@9.1.4
      

      更多步骤让更多ng serve 最终工作。

      1. 我得到的下一个错误是关于 tslib:An unhandled exception occurred: Cannot find module 'tslib' 为此,我使用 npm 手动安装了 tslib 包。
      2. 我得到的下一个错误是You seem to not be depending on "@angular/core" and/or "rxjs". This is an error.。为此,我提到了"You seem to not be depending on "@angular/core".",瞧! ng 服务成功了!

      【讨论】:

        猜你喜欢
        • 2018-09-07
        • 1970-01-01
        • 1970-01-01
        • 2022-12-24
        • 2023-02-26
        • 2017-05-05
        • 2019-04-05
        • 2020-09-03
        相关资源
        最近更新 更多