简体   繁体   English

在ngModule导入中找不到模块

[英]Module not found in ngModule imports

I have a strange problem....I use npm install to install ng-push and import PushNotificationsModule from 'ng-push' and place PushNotificationsModule in my ngModule imports. 我有一个奇怪的问题。...我使用npm install安装ng-push并从“ ng-push”导入PushNotificationsModule并将PushNotificationsModule放入我的ngModule导入中。 When I do ng build or ng build --prod both builds are success but the dev build fail when of do localhost:3000. 当我执行ng build或ng build --prod时,两个构建都成功,但是当localhost:3000时,dev构建失败。 The --prod build works. --prod构建有效。 This is the error from chrome: 这是来自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)

The package.json and appModule are: package.json和appModule为:

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

I am using the following stack: 我正在使用以下堆栈:

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

I also noticed that the sequence of my import statements are re-arranged after a build...I never saw this happen before. 我还注意到在构建之后重新排列了导入语句的顺序...我以前从未见过这种情况。

Does anyone have an idea whats going on here? 有人知道这里发生了什么吗? any help is appreciated. 任何帮助表示赞赏。

EDIT: This is from the GitHub page as to the usage: 编辑:这是从GitHub页面使用的:

Import the PushNotificationsModule in to your AppModule

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

try to import 尝试导入

PushNotificationsService PushNotificationsService

and add it in the providers collection 并将其添加到provider集合中

If you will go into the node_modules/ng-push/index.d.ts you will see PushNotificationsModule is not a node module, so you are getting that error message. 如果您进入node_modules/ng-push/index.d.ts您将看到PushNotificationsModule不是节点模块,因此您将收到该错误消息。

Below is the content of the index.d.ts 以下是index.d.ts的内容

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

Make sure you are importing the angular module from correct file. 确保从正确的文件导入角度模块。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到Angular 6的“ Fy”的NgModule元数据 - No NgModule metadata found for 'Fy', Angular 6 出现在 AppModule 的 NgModule.imports 中,但无法解析为 NgModule class. in Angular 12.2.9 - Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class. in Angular 12.2.9 编译器失败 - 找不到“AppModule”的 NgModule 元数据中的错误 - Compiler fails - ERROR in No NgModule metadata found for 'AppModule' 错误:错误:找不到&#39;AppComponent&#39;的NgModule元数据 - Error: Error: No NgModule metadata found for 'AppComponent' error NG6002:出现在AppModule的NgModule.imports中,但本身有错误 - error NG6002: Appears in the NgModule.imports of AppModule, but itself has errors 找不到节点模块。找不到模块 - node module not found .MODULE NOT FOUND JS 模块/导入节点和 ejs 的错误 - JS module/imports errors with node and ejs 使用导入和类型模块构建 typescript 应用程序时出现问题 - problem in building typescript application with imports and type module 找不到 EmailInstructorsComponent 的组件工厂。 你把它添加到@NgModule.entryComponents 了吗? - No component factory found for EmailInstructorsComponent. Did you add it to @NgModule.entryComponents? 错误:模块“AppModule”导入的意外值“HttpClient”。 请添加@NgModule 注释 - Error: Unexpected value 'HttpClient' imported by the module 'AppModule'. Please add a @NgModule annotation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM