简体   繁体   English

元数据版本不匹配Angular 4 @ ng-bootstrap

[英]Metadata version mismatch Angular 4 @ng-bootstrap

I am working on Angular bootstrap module. 我正在使用Angular Bootstrap模块。 When I install the module using following commands npm install --save @ng-bootstrap/ng-bootstrap and import the module to the main app module. 当我使用以下命令安装模块时, npm install --save @ng-bootstrap/ng-bootstrap并将模块导入到主应用程序模块。 Then I rerun getting error for the following. 然后我重新运行以下错误。

ERROR in Error: Metadata version mismatch for module F:/nodejs/angular4/mybootst
rap3/node_modules/@ng-bootstrap/ng-bootstrap/index.d.ts, found version 4, expect
ed 3, resolving symbol AppModule in F:/nodejs/angular4/mybootstrap3/src/app/app.
module.ts, resolving symbol AppModule in F:/nodejs/angular4/mybootstrap3/src/app
/app.module.ts

Here is my angular version 这是我的角度版本

@angular/cli: 1.4.4
node: 6.11.2
os: win32 ia32
@angular/animations: 4.4.6
@angular/common: 4.4.6
@angular/compiler: 4.4.6
@angular/core: 4.4.6
@angular/forms: 4.4.6
@angular/http: 4.4.6
@angular/platform-browser: 4.4.6
@angular/platform-browser-dynamic: 4.4.6
@angular/router: 4.4.6
@angular/cli: 1.4.4
@angular/compiler-cli: 4.4.6
@angular/language-service: 4.4.6
typescript: 2.3.4

Question

  • Have to install angular latest version?. 是否必须安装angular最新版本?
  • If I install latest version can I run my Angular 4 project? 如果安装最新版本,可以运行Angular 4项目吗?
  • Why I'am getting this error? 为什么我会收到此错误?

The error is caused by the fact that ng-bootstrap module version that is installed has its metadata targeted for a higher version of Angular. 该错误是由以下事实引起的:安装的ng-bootstrap模块版本具有针对更高版本Angular的元数据。 To resolve this, 为了解决这个问题,

Find out which version of ng-bootstrap is currently installed by running 通过运行找出当前安装了哪个版本的ng-bootstrap

npm list ng-bootstrap

Run the following to see all the available versions of the ng-bootstrap node module. 运行以下命令以查看ng-bootstrap节点模块的所有可用版本。

npm show ng-bootstrap@* version

Pick one version lower than what is currently installed, and install it 选择一个低于当前安装版本的版本,然后安装

npm install ng-bootstrap@x.y.z

*The xyz refers to version number. * xyz是指版本号。

Try npm start now, and see if it works. 尝试npm start现在npm start ,看看是否npm start

If it doesn't, revert to one more lower version, and retry the above step of npm install. 如果不是,请还原为另一个较低的版本,然后重试npm install的上述步骤。

Once it works - update package.json with the version number that resolved the issue so this issue doesn't appear again in the future. 一旦可行,请使用解决该问题的版本号更新package.json,以免将来再次出现此问题。 Let's say if version no. 比方说版本号。 1.3.0 solves the issue, then update the package json with. 1.3.0解决了该问题,然后使用来更新软件包json。

"@ng-bootstrap/ng-bootstrap": "1.3.0"

Remove the caret (^) if it exists, to prevent auto-selecting the highest module version available. 如果插入符(^)存在,请将其删除,以防止自动选择可用的最高模块版本。

This occurs because as of the latest version of @ng-bootstrap has issue. 发生这种情况是因为最新版本的@ ng-bootstrap出现了问题。

I solved it by changing 我通过改变解决了

 "@ng-bootstrap/ng-bootstrap": "^1.0.0-beta.5",

in the package.json to 在package.json中

 "@ng-bootstrap/ng-bootstrap": "1.0.0-beta.5",

You need specify the correct version in the package.json otherwise it will fetch the latest ng-bootstrap which has issue working with angular 4 您需要在package.json中指定正确的版本,否则它将获取最新的ng-bootstrap,该版本在使用angular 4时会出现问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM