- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我在 Angular 5 项目中添加了 NGBootstrap。但是一段时间后它不起作用,我遇到了错误。尝试通过升级 CLI 版本来解决问题,但问题仍未解决。请检查 package.json。
ERROR in src/app/app.module.ts(5,27): error TS2307: Cannot find module '@ng-bootstrap/ng-bootstrap'. src/app/find-product/searchtabcontent/search-by-family/search-by-family.component.ts(2,48): error TS2307: Cannot find module '@ng-bootstrap/ng-bootstrap'
package.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 有 NgbModule.forRoot()
这样的导入,任何其他模块应该只有 导入 []
中的 NgbModule
希望对您有所帮助:)
关于angular - 错误 TS2307 : Cannot find module '@ng-bootstrap/ng-bootstrap' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50368951/
我是一名优秀的程序员,十分优秀!