错误中的错误:NgModule不是NgModule

时间:2017-09-27 02:48:30

标签: typescript angular-cli

它工作得非常好,突然它在运行ng服务时开始给我以下异常。我没有做任何最近的升级或依赖添加的东西。

有人可以帮我解决应该采取的措施吗?

ERROR in Error: NgModule is not an NgModule
    at _getNgModuleMetadata (E:\Going-on\czc-admin-startupui\node_modules\@angular\compiler-cli\src\ngtools_impl.js:140:15)
    at _extractLazyRoutesFromStaticModule (E:\Going-on\czc-admin-startupui\node_modules\@angular\compiler-cli\src\ngtools_impl.js:109:26)
    at E:\Going-on\czc-admin-startupui\node_modules\@angular\compiler-cli\src\ngtools_impl.js:129:27
    at Array.reduce (native)
    at _extractLazyRoutesFromStaticModule (E:\Going-on\czc-admin-startupui\node_modules\@angular\compiler-cli\src\ngtools_impl.js:128:10)
    at includeLazyRouteAndSubRoutes (E:\Going-on\czc-admin-startupui\node_modules\@angular\compiler-cli\src\ngtools_impl.js:66:25)
    at Array.reduce (native)
    at includeLazyRouteAndSubRoutes (E:\Going-on\czc-admin-startupui\node_modules\@angular\compiler-cli\src\ngtools_impl.js:67:26)
    at Array.reduce (native)
    at Object.listLazyRoutesOfModule (E:\Going-on\czc-admin-startupui\node_modules\@angular\compiler-cli\src\ngtools_impl.js:54:36)
    at Function.NgTools_InternalApi_NG_2.listLazyRoutes (E:\Going-on\czc-admin-startupui\node_modules\@angular\compiler-cli\src\ngtools_api.js:91:39)
    at AotPlugin._getLazyRoutesFromNgtools (E:\Going-on\czc-admin-startupui\node_modules\@ngtools\webpack\src\plugin.js:207:44)
    at _donePromise.Promise.resolve.then.then.then.then.then (E:\Going-on\czc-admin-startupui\node_modules\@ngtools\webpack\src\plugin.js:443:24)
    at process._tickCallback (internal/process/next_tick.js:109:7)

webpack: Failed to compile.

我的package.json文件:

{
  "name": "sb-admin-angular4-bootstrap4",
  "version": "1.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --ec=true",
    "build": "ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^4.4.3",
    "@angular/cli": "^1.4.3",
    "@angular/common": "^4.4.3",
    "@angular/compiler": "^4.4.3",
    "@angular/compiler-cli": "^4.4.3",
    "@angular/core": "^4.4.3",
    "@angular/forms": "^4.4.3",
    "@angular/http": "^4.4.3",
    "@angular/platform-browser": "^4.4.3",
    "@angular/platform-browser-dynamic": "^4.4.3",
    "@angular/platform-server": "^4.4.3",
    "@angular/router": "^4.4.3",
    "@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.25",
    "@ngx-translate/core": "^6.0.1",
    "@ngx-translate/http-loader": "0.0.3",
    "@swimlane/ngx-datatable": "^9.3.0",
    "angular2-datatable": "^0.6.0",
    "angular2-multiselect-dropdown": "^1.2.2",
    "core-js": "^2.4.1",
    "font-awesome": "^4.7.0",
    "ionicons": "^3.0.0",
    "ng-block-ui": "^1.0.0-beta.15",
    "ng-spin-kit": "^5.1.1",
    "ng2-charts": "^1.5.0",
    "rxjs": "^5.1.0",
    "typescript": "^2.3.4",
    "zone.js": "^0.8.4"
  },
  "devDependencies": {
    "@angular/cli": "^1.4.3",
    "@angular/compiler-cli": "^4.0.0",
    "@types/jasmine": "2.5.38",
    "@types/node": "~6.0.60",
    "codelyzer": "~2.0.0",
    "jasmine-core": "~2.5.2",
    "jasmine-spec-reporter": "~3.2.0",
    "karma": "~1.4.1",
    "karma-chrome-launcher": "~2.0.0",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^0.2.0",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "karma-phantomjs-launcher": "^1.0.4",
    "protractor": "~5.1.0",
    "ts-node": "~2.0.0",
    "tslint": "~4.5.0",
    "typescript": "~2.2.0"
  }
}

我卸载,安装并再次尝试,但没有运气。尝试使用最新的打字稿版本,但获得了一些其他例外,因此还原了这些更改。

1 个答案:

答案 0 :(得分:0)

我犯了一个非常愚蠢的错误,NgModule也加入了进口。我刚删除它然后解决了这个问题。

using System;
using System.Collections.Generic;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

namespace TestPrint
{
    /// <summary>
    /// Page content to send to the printer
    /// </summary>
    public sealed partial class PageToPrint : Page
    {
        public RichTextBlock TextContentBlock { get; set; }

        public PageToPrint()
        {
            this.InitializeComponent();
            TextContentBlock = TextContent;
            MyWebView.LoadCompleted += MyWebView_LoadCompletedAsync;
        }

        async void MyWebView_LoadCompletedAsync(object sender, NavigationEventArgs e)
        {
            MyWebViewRectangle.Fill = await GetWebViewBrushAsync(MyWebView);
            MyPrintPages.ItemsSource = await GetWebPagesAsync(MyWebView, new Windows.Foundation.Size(100d, 150d));
            MyWebView.Visibility = Windows.UI.Xaml.Visibility.Visible;
        }

        async System.Threading.Tasks.Task<WebViewBrush> GetWebViewBrushAsync(WebView webView)
        {
            // resize width to content
            var _OriginalWidth = webView.Width;
            var _WidthString = await webView.InvokeScriptAsync("eval",
                new[] { "document.body.scrollWidth.toString()" });
            int _ContentWidth;
            if (!int.TryParse(_WidthString, out _ContentWidth))
                throw new Exception(string.Format("failure/width:{0}", _WidthString));
            webView.Width = _ContentWidth;

            // resize height to content
            var _OriginalHeight = webView.Height;
            var _HeightString = await webView.InvokeScriptAsync("eval",
                new[] { "document.body.scrollHeight.toString()" });
            int _ContentHeight;
            if (!int.TryParse(_HeightString, out _ContentHeight))
                throw new Exception(string.Format("failure/height:{0}", _HeightString));
            webView.Height = _ContentHeight;

            // create brush
            var _OriginalVisibilty = webView.Visibility;
            webView.Visibility = Windows.UI.Xaml.Visibility.Visible;
            var _Brush = new WebViewBrush
            {
                SourceName = webView.Name,
                Stretch = Stretch.Uniform
            };
            _Brush.Redraw();

            // reset, return
            webView.Width = _OriginalWidth;
            webView.Height = _OriginalHeight;
            webView.Visibility = _OriginalVisibilty;
            return _Brush;
        }

        async System.Threading.Tasks.Task<IEnumerable<FrameworkElement>> GetWebPagesAsync(WebView webView, Windows.Foundation.Size page)
        {
            // ask the content its width
            var _WidthString = await webView.InvokeScriptAsync("eval",
                new[] { "document.body.scrollWidth.toString()" });
            int _ContentWidth;
            if (!int.TryParse(_WidthString, out _ContentWidth))
                throw new Exception(string.Format("failure/width:{0}", _WidthString));
            webView.Width = _ContentWidth;

            // ask the content its height
            var _HeightString = await webView.InvokeScriptAsync("eval",
                new[] { "document.body.scrollHeight.toString()" });
            int _ContentHeight;
            if (!int.TryParse(_HeightString, out _ContentHeight))
                throw new Exception(string.Format("failure/height:{0}", _HeightString));
            webView.Height = _ContentHeight;

            // how many pages will there be?
            var _Scale = page.Width / _ContentWidth;
            var _ScaledHeight = (_ContentHeight * _Scale);
            var _PageCount = (double)_ScaledHeight / page.Height;
            _PageCount = _PageCount + ((_PageCount > (int)_PageCount) ? 1 : 0);

            // create the pages
            var _Pages = new List<Windows.UI.Xaml.Shapes.Rectangle>();
            for (int i = 0; i < (int)_PageCount; i++)
            {
                var _TranslateY = -page.Height * i;
                var _Page = new Windows.UI.Xaml.Shapes.Rectangle
                {
                    Height = page.Height,
                    Width = page.Width,
                    Margin = new Thickness(5),
                    Tag = new TranslateTransform { Y = _TranslateY },
                };
                _Page.Loaded += async (s, e) =>
                {
                    var _Rectangle = s as Windows.UI.Xaml.Shapes.Rectangle;
                    var _Brush = await GetWebViewBrushAsync(webView);
                    _Brush.Stretch = Stretch.UniformToFill;
                    _Brush.AlignmentY = AlignmentY.Top;
                    _Brush.Transform = _Rectangle.Tag as TranslateTransform;
                    _Rectangle.Fill = _Brush;
                };
                _Pages.Add(_Page);
            }
            return _Pages;
        }
    }
}

已解决的代码:(从导入中删除了NgModule)

import { NgModule } from '@angular/core';
import { AddBannerComponent } from './add-banner/add-banner.component';
import { BannerComponent } from './banner.component';
import { BannerRoutingModule } from './banner-routing.module';

@NgModule({
  imports:[NgModule,BannerRoutingModule],
  declarations:[AddBannerComponent,BannerComponent],
  providers:[]
})
export class BannerModule{

}
相关问题