Angular 6 ng build Cannot read property 'length' of undefined TypeError: Cannot read property 'length' of undefined at levenshtein

Angular 6 ng build Cannot read property 'length' of undefined TypeError: Cannot read property 'length' of undefined at levenshtein

我发现了这个错误 in another question 但没有解决,所以我想问是否有人可以帮我解决这个问题:

我正在使用 Angular 6 & 如果我使用 ng s 应用程序在本地运行得很好,也使用 ng s --aot 工作正常,但是,如果我从 angular 构建生产版本,我会收到以下错误,而没有任何参考它的原因(在我的代码中)

注意: 我之前已经成功制作了多个产品构建

如何找出是哪个变量或 属性 导致的?

谢谢

ng -build -prod
    Cannot read property 'length' of undefined
    TypeError: Cannot read property 'length' of undefined
        at levenshtein (D:Angular\node_modules\@angular\cli\models\command-runner.js:58:23)
        at listAllCommandNames.sort (D:Angular\node_modules\@angular\cli\models\command-runner.js:69:43)
        at Array.sort (native)
        at Object.<anonymous> (D:Angular\node_modules\@angular\cli\models\command-runner.js:67:65)
        at Generator.next (<anonymous>)
        at D:Angular\node_modules\@angular\cli\models\command-runner.js:7:71
        at new Promise (<anonymous>)
        at __awaiter (D:Angular\node_modules\@angular\cli\models\command-runner.js:3:12)
        at Object.runCommand (D:Angular\node_modules\@angular\cli\models\command-runner.js:28:12)
        at D:Angular\node_modules\@angular\cli\lib\cli\index.js:60:58

感谢 hrdkisback 的精彩评论,我发现了问题

我遇到了同样的错误,我花了几个小时才解决,因为这个错误误导了我,实际上是因为我尝试了这 2 个错误的命令:

ng -build -prod
ng -build --prod

上面的两个命令都出现了这个错误,所以我认为我的代码有问题并一直在寻找它,解决方案只是使用下面的正确命令:

ng build --prod