1

When trying to create a enum with the Angular CLI, I get the following error:

C:\angular\myapp\src\app\enums>ng generate enum myEnum
installing enum
Cannot read property '0' of undefined
TypeError: Cannot read property '0' of undefined
    at Object.getAppFromConfig (C:\angular\myapp\node_modules\@angular\cli\utilities\app-utils.js:4:19)
    at Class.normalizeEntityName (C:\angular\myapp\node_modules\@angular\cli\blueprints\enum\index.js:18:39)
    at Class.Blueprint._normalizeEntityName (C:\angular\myapp\node_modules\@angular\cli\ember-cli\lib\models\blueprint.js:454:24)
    at Class.Blueprint.install (C:\angular\myapp\node_modules\@angular\cli\ember-cli\lib\models\blueprint.js:513:8)
    at Class.run (C:\angular\myapp\node_modules\@angular\cli\ember-cli\lib\tasks\generate-from-blueprint.js:59:49)
    at Class.run (C:\angular\myapp\node_modules\@angular\cli\ember-cli\lib\commands\generate.js:71:17)
    at Class.<anonymous> (C:\angular\myapp\node_modules\@angular\cli\ember-cli\lib\models\command.js:134:17)
    at process._tickCallback (internal/process/next_tick.js:103:7)

Does someone know if this is a bug on Angular CLI or am I creating enums incorrectly?

I am currently working on Angular CLI version : 1.0.0-rc.0

Wayne Barnard
  • 164
  • 1
  • 8
  • Have you performed a clean reinstall/install of *global* and *project local* `angular-cli`? Also nuking the `node_modules/` might help in cases as this one. – Yuri Mar 08 '17 at 13:39
  • Thanks for the reply, seems just upgrading the CLI version did the trick. – Wayne Barnard Mar 10 '17 at 07:10

2 Answers2

0

I ran into this issue today too when I tried to run the Angular Quickstart zip package. If you debug that app-utils.js in that error you posted you can see the error. I opened that file in a text editor and did a console.log above that line in the error. That line is trying to load angular-cli.json file and that file was missing in my case (from the quickstart zip file).

Make a new angular-cli.json file in that directory you're running this command in (in my case, it was the root) and use the content in my demo repo below. Then run the ng generate ... command again. That worked for me, hope it works for you too.

Note that my angular-cli.json is using polyfill.ts, and tsconfig.app.json (anyhow everything is there)

https://github.com/zagros/stack-overflow_angular-cli-enum-creation-error

If you're after i18n support, this may also interest you. The only problem i'm having right now is that node_modules\.bin\ng-xi18n -p src\tsconfig.json command needs the template URL's be relative to the TS file, while the ng start needs them to start with app\name.of.template.html. So I manually change the paths using an external script I wrote for the time-being, generate my XLIFF files, then change the paths back. If you're not using XLIFF i18n ignore this bit.

zagros
  • 134
  • 5
0

So...

I managed to fix the issue... Just upgrade to RC.1 and voila! it works!

So i`m not sure if it was a bug on RC.0 or something, but at least its working now...

Wayne Barnard
  • 164
  • 1
  • 8