[英]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.