angular - 错误 TS2307:找不到模块“@ng-bootstrap/ng-bootstrap”
问题描述
我在 Angular 5 项目中添加了 NGBootstrap。但过了一段时间它不起作用,我得到了错误。尝试通过升级 CLI 版本来解决问题,但问题仍未解决。请检查 package.json。
src/app/app.module.ts(5,27) 中的错误:错误 TS2307:找不到模块“@ng-bootstrap/ng-bootstrap”。src/app/find-product/searchtabcontent/search-by-family/search-by-family.component.ts(2,48): 错误 TS2307: 找不到模块'@ng-bootstrap/ng-bootstrap'
包.json
{
"name": "ng5",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.conf.json",
"build": "ng build --prod --base-href=/UI/pages/",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^5.2.0",
"@angular/common": "^5.2.0",
"@angular/compiler": "^5.2.0",
"@angular/core": "^5.2.0",
"@angular/forms": "^5.2.0",
"@angular/http": "^5.2.0",
"@angular/platform-browser": "^5.2.0",
"@angular/platform-browser-dynamic": "^5.2.0",
"@angular/router": "^5.2.0",
"@ng-bootstrap/ng-bootstrap": "^1.1.2",
"core-js": "^2.4.1",
"rxjs": "^5.5.6",
"zone.js": "^0.8.19"
},
"devDependencies": {
"@angular/cli": "^6.0.1",
"@angular/compiler-cli": "^5.2.0",
"@angular/language-service": "^5.2.0",
"@types/jasmine": "~2.8.3",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "^4.0.1",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "~2.5.3",
"@angular-devkit/build-angular": "~0.6.1"
}
}
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
NgbModule.forRoot(),
BrowserModule,
AppRoutingModule,
FormsModule,
HttpClientModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
解决方案
如果您在删除 node_modules 后已经尝试重新npm install
,问题仍然存在,并且您还仔细检查了“@ng-bootstrap”是否在您的 node_modules 目录下,我将按照以下步骤进行:
我会尝试首先重新启动 IDE,Visual Studio Code 和其他人也会发生这种情况......
你也可以试试这个(这适用于linux):
sudo npm install --save @ng-bootstrap/ng-bootstrap
cd @ng-bootstrap
sudo npm install
确保,如果你有多个模块,只有 app.module 有 import like
NgbModule.forRoot()
,任何其他模块应该只NgbModule
在 import []
希望能帮助到你 :)
推荐阅读
- mysql - 在 MYSQL 中加入 Count 或 Sum
- hadoop - PIG:要排列在特定列集中的多个记录
- regex - 如何使用正则表达式替换字符串的一部分
- c# - 我想要以(开始,结束)为键的数据结构,然后能够在整个数据结构中搜索整数并获得相应的值
- angularjs - AngularJS 文件上传、Express 和 node-postgres (pg)
- sql-server - UNION 和 NOT 在一起
- python - 一个热门编码句子
- mapstruct - 使用 Immutables 时关闭 MapStruct 中的“构建器”
- javascript - 如何自动重新加载 div 内容
- google-apps-script - SpreadsheetApp.openByID 的突然权限问题