Angular import npm模块不起作用
问题描述:
我有一个angular-cli应用程序,我也创建了一个模块作为npm包。这是结构:Angular import npm模块不起作用
--otherModule
--other-module.module.ts
--index.ts
--package.json
index.ts:
export { OtherModule } from './other-module.module';
其他-module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';;
@NgModule({
declarations: [ OtherComponent ],
imports: [
CommonModule
],
})
export class OtherModule {
}
运行NPM链接后我试图用这个模块在我的角度cli应用是这样的:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { OtherModule } from 'other-module';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
OtherModule
],
providers: [],
bootstrap: [ AppComponent ]
})
export class AppModule {
}
但后来我发现了以下错误:
Unexpected value 'OtherModule' imported by the module 'AppModule'. Please add a @NgModule annotation.
好像装饰不工作或东西。有任何想法吗?
答
我正面临着这样的问题,我通过删除链接文件夹中的node_modules文件夹窗体来修复它。
对于您来说,修复应该从--otherModule
文件夹中删除node_modules。这样,npm不会在里面搜索。
我不知道你是否面临同样的问题,但值得一试。
答
我遇到了同样的问题,在删除了其他模块的node_modules和从父应用程序执行的npm-installing后解决了。
但是,必须不断安装和卸载库的node_modules(安装需要用于构建,测试,并且IDE需要知道依赖项中的类型),这会使开发非常繁琐。
你能否提供other-module.module.ts? – JEY
是的,我更新了答案 – ng2user