Angular CLI - Typescript throws: Cannot read property 'length' of undefined

前端 未结 9 2024
春和景丽
春和景丽 2021-02-07 04:24

I run in angular 4 project with ng serve and i get error

Cannot read property \'length\' of undefined

but I don\'t have any property length in

相关标签:
9条回答
  • 2021-02-07 04:30

    My error was caused by c&p error when creating a small component. I forgot to change path to component's template and styles.

    0 讨论(0)
  • 2021-02-07 04:41

    Close the running port and Try rebuilding the app with "ng build"

    0 讨论(0)
  • 2021-02-07 04:47

    Could be bad path to component templateUrl, perhaps missing the ./

    Before: templateUrl: 'my-control.component.html',

    After: templateUrl: './my-control.component.html',

    0 讨论(0)
  • 2021-02-07 04:48

    Most likely you have changed around your modules in a way that needs the CLI to be restarted.

    I had the same error running ng serve after removing a component from a module. By restarting that process and re running ng serve the error went away.

    0 讨论(0)
  • 2021-02-07 04:50

    In my case I did the following and it solved the issue:

    1. Create environments folder (if not exist) in src of the Project C:\Users\abcd\Desktop\MyApp\src

    2. Put the two files environment.ts and environment.prod.ts in environments folder.

    0 讨论(0)
  • 2021-02-07 04:50

    In my case, it's mysterious. But it won't hurt to offer what I had witnessed and maybe a bit history. None or maybe some historical event might have caused it but I really don't know.

    • Everything is good. Angular 8 running inside 18.04.4 LTS (Bionic Beaver)LXC within 19.10 ubuntu host with npm 6.14.2, node10.16.3
    • Upgraded host to 20.04 LTS(Focal Fossa). Write some code. Remove a package called angular-shepherd. Try to build --prod. This errors shows up during angular Generating ES5 bundles.
    • Tried everything. All failed.
    • Reset what I did inside the project. Still fail.
    • Reboot LXC.
    • Fixed.
    0 讨论(0)
提交回复
热议问题