问题
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
回答1:
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
回答2:
I believe, that this error appears, when wrong argument is used. Try to use
ng serve -o
回答3:
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.
来源:https://stackoverflow.com/questions/50306105/getting-error-in-angular-6-cannot-read-property-length-of-undefined