3
votes

Cannot read property 'length' of undefined TypeError: Cannot read property 'length' of undefined at levenshtein (F:\Learnings\AngularHandsOn\Angular6\angular6Handson\node_modules\@angular\cli\models\command-runner.js:58:23) at listAllCommandNames.sort (F:\Learnings\AngularHandsOn\Angular6\angular6Handson\node_modules\@angular\cli\models\command-runner.js:69:43) at Array.sort (native) at Object. (F:\Learnings\AngularHandsOn\Angular6\angular6Handson\node_modules\@angular\cli\models\command-runner.js:67:65) at Generator.next () at F:\Learnings\AngularHandsOn\Angular6\angular6Handson\node_modules\@angular\cli\models\command-runner.js:7:71 at new Promise () at __awaiter (F:\Learnings\AngularHandsOn\Angular6\angular6Handson\node_modules\@angular\cli\models\command-runner.js:3:12) at Object.runCommand (F:\Learnings\AngularHandsOn\Angular6\angular6Handson\node_modules\@angular\cli\models\command-runner.js:28:12) at F:\Learnings\AngularHandsOn\Angular6\angular6Handson\node_modules\@angular\cli\lib\cli\index.js:60:58

When I am directly pasting url in browser then all are working fine even its not showing any error in console window. But when I use ng -o command then it shows me error.

I am using angular cli 6.0.0

3

3 Answers

3
votes

I got the same error & it took me hours to resolve because the error was misleading to me, it was actually because I tried these 2 incorrect commands:

ng -build -prod
ng -build --prod

Both of the above commands gave that error, so I thought I have a problem in my code & kept looking for it, the solution was simply to use the correct command below:

ng build --prod
1
votes

I believe, that this error appears, when wrong argument is used. Try to use

ng serve -o
0
votes

I also received this error when I forgot to change templateUrl to template in the @Component decorator after moving a template from an external file to inline.