簡體   English   中英

在ngModule導入中找不到模塊

[英]Module not found in ngModule imports

我有一個奇怪的問題。...我使用npm install安裝ng-push並從“ ng-push”導入PushNotificationsModule並將PushNotificationsModule放入我的ngModule導入中。 當我執行ng build或ng build --prod時,兩個構建都成功,但是當localhost:3000時,dev構建失敗。 --prod構建有效。 這是來自chrome的錯誤:

 compiler.js:15989 Uncaught Error: Unexpected value 'PushNotificationsModule' imported by the module 'AppModule'. Please add a @NgModule annotation.
    at syntaxError (compiler.js:486)
    at compiler.js:15240
    at Array.forEach (<anonymous>)
    at CompileMetadataResolver.push../node_modules/@angular/compiler/esm5/compiler.js.CompileMetadataResolver.getNgModuleMetadata (compiler.js:15215)
    at JitCompiler.push../node_modules/@angular/compiler/esm5/compiler.js.JitCompiler._loadModules (compiler.js:34413)
    at JitCompiler.push../node_modules/@angular/compiler/esm5/compiler.js.JitCompiler._compileModuleAndComponents (compiler.js:34374)
    at JitCompiler.push../node_modules/@angular/compiler/esm5/compiler.js.JitCompiler.compileModuleAsync (compiler.js:34268)
    at CompilerImpl.push../node_modules/@angular/platform-browser-dynamic/esm5/platform-browser-dynamic.js.CompilerImpl.compileModuleAsync (platform-browser-dynamic.js:239)
    at PlatformRef.push../node_modules/@angular/core/esm5/core.js.PlatformRef.bootstrapModule (core.js:5578)
    at Module../src/main.ts (main.ts:16)

package.json和appModule為:

package.json:
 "ng-push": "0.2.0",
appModule:
import { PushNotificationsModule } from 'ng-push';
@NgModule({
  imports: [
    BrowserAnimationsModule,
    BrowserModule,
    ........
    ........
    MultipleDatePickerModule,
    ChartsModule,
    PushNotificationsModule,
    .......
  ]

我正在使用以下堆棧:

Angular CLI: 6.2.9
Node: 8.11.4
OS: win32 x64
Angular: 5.2.11
... animations, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic
... platform-server, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.8.9
@angular-devkit/build-angular     0.8.9
@angular-devkit/build-optimizer   0.8.9
@angular-devkit/build-webpack     0.8.9
@angular-devkit/core              0.8.9
@angular-devkit/schematics        0.8.9
@angular/cdk                      5.2.5
@angular/cli                      6.2.9
@angular/material                 5.2.5
@ngtools/webpack                  6.2.9
@schematics/angular               0.8.9
@schematics/update                0.8.9
rxjs                              5.5.12
typescript                        2.5.3
webpack                           4.16.4

我還注意到在構建之后重新排列了導入語句的順序...我以前從未見過這種情況。

有人知道這里發生了什么嗎? 任何幫助表示贊賞。

編輯:這是從GitHub頁面使用的:

Import the PushNotificationsModule in to your AppModule

@NgModule({
    imports: [PushNotificationsModule],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }

嘗試導入

PushNotificationsService

並將其添加到provider集合中

如果您進入node_modules/ng-push/index.d.ts您將看到PushNotificationsModule不是節點模塊,因此您將收到該錯誤消息。

以下是index.d.ts的內容

export * from './services/push-notifications.service';
export * from './interfaces/push-notification.type';
export declare class PushNotificationsModule {
}

確保從正確的文件導入角度模塊。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM