我的应用程序中有一个ngx引导程序的问题,除非您指定路径,否则它现在无法检测模块。
例如:
import { BsModalService, BsModalRef } from 'ngx-bootstrap';生成“无法找到模块‘ngx-引导程序’”。
移除引用并检查快速修复时,只需将引用替换为:
import { BsModalService, BsModalRef} from 'ngx-bootstrap/modal/public_api';显然,这并不理想,因为它们应该可以通过ngx引导程序获得,而不需要指定文件夹,而且我需要查看几十个组件并更改这些引用,这些引用不应该是必需的。以前有人遇到过这个问题吗?
我已经试过了
npm installnpm updatenpm installnpm install ngx-bootstrap --savenpm cache cleannpm install,同样的事情也发生了昨天一切都很顺利。我不知道我错过了什么。
更多信息:
Angular CLI: 9.0.2
Node: 12.16.1
OS: win32 x64
Angular: 9.0.1package.json:
"private": true,
"dependencies": {
"@agm/core": "^1.1.0",
"@angular-devkit/build-angular": "^0.900.7",
"@angular/animations": "9.0.1",
"@angular/cdk": "^9.2.0",
"@angular/common": "9.0.1",
"@angular/compiler": "9.0.1",
"@angular/core": "9.0.1",
"@angular/forms": "9.0.1",
"@angular/platform-browser": "9.0.1",
"@angular/platform-browser-dynamic": "9.0.1",
"@angular/router": "9.0.1",
"@auth0/angular-jwt": "^4.0.0",
"@microsoft/signalr": "^3.1.3",
"@ng-select/ng-select": "^3.7.3",
"@ngx-progressbar/core": "^5.3.2",
"@ngx-pwa/local-storage": "^9.0.3",
"@types/date-fns": "^2.6.0",
"angular-9-datatable": "^0.1.1",
"angular-calendar": "^0.28.2",
"angular-gauge": "^3.1.2",
"angular-gridster2": "^9.0.1",
"angular-resize-event": "^1.2.1",
"bootstrap": "^4.4.1",
"chartjs-plugin-annotation": "^0.5.7",
"ckeditor4-angular": "^1.1.0",
"core-js": "^3.6.4",
"crypto-js": "^4.0.0",
"echarts": "^4.7.0",
"file-saver": "^2.0.2",
"html2canvas": "^1.0.0-rc.5",
"jspdf": "^1.5.3",
"moment": "^2.24.0",
"moment-timezone": "^0.5.27",
"ng-dynamic-component": "^6.1.0",
"ng2-dragula": "^2.1.1",
"ng4-charts": "^1.0.2",
"ngx-bootstrap": "^5.3.2",
"ngx-color": "^4.1.1",
"ngx-echarts": "^4.2.2",
"ngx-image-compress": "^8.0.4",
"ngx-image-cropper": "^3.1.5",
"ngx-infinite-scroll": "^8.0.1",
"ngx-material-timepicker": "^5.5.1",
"ngx-pagination": "^5.0.0",
"ngx-swiper-wrapper": "^9.0.1",
"ngx-toastr": "^12.0.1",
"pluralize": "^8.0.0",
"rxjs": "6.5.4",
"rxjs-compat": "6.5.4",
"time-ago-pipe": "^1.3.2",
"tslib": "^1.10.0",
"valid-url": "^1.0.9",
"zone.js": "^0.10.3"
},
"devDependencies": {
"@angular/cli": "9.0.2",
"@angular/compiler-cli": "9.0.1",
"@angular/language-service": "9.0.1",
"@types/echarts": "^4.4.4",
"@types/file-saver": "^2.0.1",
"@types/googlemaps": "^3.39.2",
"@types/jasmine": "3.5.3",
"@types/jasminewd2": "2.0.8",
"@types/jspdf": "^1.3.3",
"@types/node": "^13.9.8",
"@types/pluralize": "0.0.29",
"@types/valid-url": "^1.0.3",
"codelyzer": "^5.2.2",
"ie-shim": "^0.1.0",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^4.4.1",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~2.1.1",
"karma-jasmine": "~3.1.1",
"karma-jasmine-html-reporter": "^1.5.3",
"node-sass": "^4.13.1",
"protractor": "~5.4.3",
"ts-node": "~8.6.2",
"tslint": "~6.0.0",
"typescript": "3.7.5",
"webpack-bundle-analyzer": "^3.6.1"
},如果有人有任何想法告诉我
谢谢!
发布于 2020-04-11 14:54:43
基于ngx-引导文档,angular 9不支持这种导入。如果您想使用BsModalService、ButtonsModule等,您必须导入它们,如下所示:
// RECOMMENDED
import { BsModalService, BsModalRef } from 'ngx-bootstrap/modal';
import { ButtonsModule } from 'ngx-bootstrap/buttons';而不是:
// NOT RECOMMENDED
import { BsModalService, BsModalRef , ButtonsModule } from 'ngx-bootstrap';发布于 2020-04-10 09:31:05
根据https://github.com/valor-software/ngx-bootstrap/issues/5753
更新文档:https://valor-software.com/ngx-bootstrap/#/modals
// RECOMMENDED
import { ModalModule } from 'ngx-bootstrap/modal';
// NOT RECOMMENDED (Angular 9 doesn't support this kind of import)
import { ModalModule } from 'ngx-bootstrap';
@NgModule({
imports: [ModalModule.forRoot(),...]
})
export class AppModule(){}这是理想的解决方案,因为它是一个由维护人员记录的回购。
发布于 2020-04-07 16:13:48
我今天也遇到了同样的问题,试图从角9.0.2升级到角9.1.0。
我想这是因为您的package.json:“ngx-引导程序”:"^5.3.2"中包含了最新版本,因此npm采用了ngx上的最新版本:5.6.0。(至少这是我今天的版本)
我已经解决了,只是替换了代码的导入,从'ngx-bootstrap'到'ngx-bootstrap/someBootstrapComponent'.
例如,我以前的导入是:
import { BsModalRef, BsModalService } from 'ngx-bootstrap';我的新进口看起来是:
import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal';我知道这不是一个理想的解决方案,但同时,至少你可以让你的应用程序编译正确。
希望能帮上忙。
向你问好,热苏斯。
https://stackoverflow.com/questions/61083880
复制相似问题