无法读取角度4中未定义的属性“长度”
2017-06-13
16561
我是 Angular 4 的新手,正在尝试弄清一个简单项目的基本结构。我已经测试了我的项目,昨天运行良好。但是今天当我打开我的项目并想要执行“ng serve”时,它显示以下错误。不知道问题是什么。
TypeError: Cannot read property 'length' of undefined
at createSourceFile (C:\Users\IR\Desktop\angular-first-project\node_modules\typescript\lib\typescript.js:15457:109)
at parseSourceFileWorker (C:\Users\IR\Desktop\angular-first-project\node_modules\typescript\lib\typescript.js:15389:26)
at Object.parseSourceFile (C:\Users\IR\Desktop\angular-first-project\node_modules\typescript\lib\typescript.js:15338:26)
at Object.createSourceFile (C:\Users\IR\Desktop\angular-first-project\node_modules\typescript\lib\typescript.js:15192:29)
at VirtualFileStats.getSourceFile (C:\Users\IR\Desktop\angular-first-project\node_modules\@ngtools\webpack\src\compiler_host.js:66:35)
at WebpackCompilerHost.getSourceFile (C:\Users\IR\Desktop\angular-first-project\node_modules\@ngtools\webpack\src\compiler_host.js:213:38)
at findSourceFile (C:\Users\IR\Desktop\angular-first-project\node_modules\typescript\lib\typescript.js:67909:29)
at processImportedModules (C:\Users\IR\Desktop\angular-first-project\node_modules\typescript\lib\typescript.js:68056:25)
at findSourceFile (C:\Users\IR\Desktop\angular-first-project\node_modules\typescript\lib\typescript.js:67937:17)
at processSourceFile (C:\Users\IR\Desktop\angular-first-project\node_modules\typescript\lib\typescript.js:67840:27)
at processRootFile (C:\Users\IR\Desktop\angular-first-project\node_modules\typescript\lib\typescript.js:67728:13)
at C:\Users\IR\Desktop\angular-first-project\node_modules\typescript\lib\typescript.js:67018:60
at Object.forEach (C:\Users\IR\Desktop\angular-first-project\node_modules\typescript\lib\typescript.js:1449:30)
at Object.createProgram (C:\Users\IR\Desktop\angular-first-project\node_modules\typescript\lib\typescript.js:67018:16)
at AotPlugin._setupOptions (C:\Users\IR\Desktop\angular-first-project\node_modules\@ngtools\webpack\src\plugin.js:129:28)
at new AotPlugin (C:\Users\IR\Desktop\angular-first-project\node_modules\@ngtools\webpack\src\plugin.js:26:14)
提前致谢。
3个回答
我曾在随机场合看到过此类错误,例如将组件移动到不同的文件夹后,甚至在更改所有引用以匹配新路径后也是如此。
使用 ng-build 重建项目应该会有所帮助。
Ľuboš Pilka
2017-10-13
是的,我更改了文件夹并收到该错误。构建后它就正常工作了
Dogan UGUR
2017-10-25