删除组件时Angular App不编译

时间:2017-12-04 17:09:58

标签: javascript angular webpack

当我删除一个组件时(比如nav-bar.component.ts和它的文件夹),该应用程序无法编译。我已从app.module.ts中删除了声明。抛出的错误说它与“include.module.ts”有关,这与nav-bar.component.ts没有关系。

这是CLI输出:

C:\Users\Daniel\dev-projects\vile>ng serve
** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
Date: 2017-12-04T17:02:37.587Z
Hash: d00b13e972db5b32e6b8
Time: 2988ms
chunk {inline} inline.bundle.js, inline.bundle.js.map (inline) 5.83 kB [entry] [rendered]
chunk {main} main.bundle.js, main.bundle.js.map (main) 1.06 kB {vendor} [initial] [rendered]
chunk {polyfills} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 323 bytes {inline} [initial] [rendered]
chunk {styles} styles.bundle.js, styles.bundle.js.map (styles) 56.5 kB {inline} [initial] [rendered]
chunk {vendor} vendor.bundle.js, vendor.bundle.js.map (vendor) 338 kB [initial] [rendered]

ERROR in Error: Metadata version mismatch for module C:/Users/Daniel/dev-projects/vile/node_modules/@angular/material/toolbar/typings/index.d.ts, found version 4, expected 3, resolving symbol IncludeModule in C:/Users/Daniel/dev-projects/vile/src/app/include/include.module.ts, resolving symbol IncludeModule in C:/Users/Daniel/dev-projects/vile/src/app/include/include.module.ts
    at Error (native)
    at syntaxError (C:\Users\Daniel\dev-projects\vile\node_modules\@angular\compiler\bundles\compiler.umd.js:1729:34)
    at simplifyInContext (C:\Users\Daniel\dev-projects\vile\node_modules\@angular\compiler\bundles\compiler.umd.js:24979:23)
    at StaticReflector.simplify (C:\Users\Daniel\dev-projects\vile\node_modules\@angular\compiler\bundles\compiler.umd.js:24991:13)
    at StaticReflector.annotations (C:\Users\Daniel\dev-projects\vile\node_modules\@angular\compiler\bundles\compiler.umd.js:24418:41)
    at _getNgModuleMetadata (C:\Users\Daniel\dev-projects\vile\node_modules\@angular\compiler-cli\src\ngtools_impl.js:138:31)
    at _extractLazyRoutesFromStaticModule (C:\Users\Daniel\dev-projects\vile\node_modules\@angular\compiler-cli\src\ngtools_impl.js:109:26)
    at C:\Users\Daniel\dev-projects\vile\node_modules\@angular\compiler-cli\src\ngtools_impl.js:129:27
    at Array.reduce (native)
    at _extractLazyRoutesFromStaticModule (C:\Users\Daniel\dev-projects\vile\node_modules\@angular\compiler-cli\src\ngtools_impl.js:128:10)
    at Object.listLazyRoutesOfModule (C:\Users\Daniel\dev-projects\vile\node_modules\@angular\compiler-cli\src\ngtools_impl.js:53:22)
    at Function.NgTools_InternalApi_NG_2.listLazyRoutes (C:\Users\Daniel\dev-projects\vile\node_modules\@angular\compiler-cli\src\ngtools_api.js:91:39)
    at AotPlugin._getLazyRoutesFromNgtools (C:\Users\Daniel\dev-projects\vile\node_modules\@ngtools\webpack\src\plugin.js:207:44)
    at _donePromise.Promise.resolve.then.then.then.then.then (C:\Users\Daniel\dev-projects\vile\node_modules\@ngtools\webpack\src\plugin.js:443:24)
    at process._tickCallback (internal/process/next_tick.js:109:7)

webpack: Failed to compile.

3 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,我通过使用 ctrl+c 停止应用程序并重新运行“ng serve”命令来解决它。

答案 1 :(得分:1)

运行 ng serve 命令对我不起作用。但是,我收到此错误的原因是没有保存 module.ts 文件。确保保存所有文件。希望它有效。

答案 2 :(得分:0)

我弄明白了这个问题。我在include.module.ts(导入其他模块的模块)中导入了导出到nav-bar.module.ts的模块(来自'@ angular / material / toolbar'的MatToolbarModule)。出于某种原因,尽管include.module.ts导出MatToolbarModule应该没有问题,但它无法编译。我的简单修复:删除MatToolbarModule的import语句并将其重新放回。