使用PrimeNg时找不到模块'@ angular / core'

时间:2018-01-26 13:51:32

标签: angular npm dependencies primeng

我已经安装了PrimeNg并尝试使用侧边栏组件但是当我运行我的项目时出现此错误

ERROR in /home/haddad/projects/node_modules/primeng/components/sidebar/sidebar.d.ts (1,97): Cannot find module '@angular/core'.
ERROR in Error: Metadata version mismatch for module /home/haddad/projects/node_modules/primeng/components/sidebar/sidebar.d.ts, found version 4, expected 3, resolving symbol AppModule in /home/haddad/projects/ar/arrt/src/app/app.module.ts, resolving symbol AppModule in /home/haddad/projects/ar/arrt/src/app/app.module.ts

我应该使用angular 4,所以我将PrimeNg版本修改为4.2.1而不是5v

这是 package.json 文件

"dependencies": {
  "@angular/animations": "^4.3.4",
  "@angular/common": "~4.3.4",
  "@angular/compiler": "~4.3.4",
  "@angular/core": "~4.3.4",
  "@angular/forms": "~4.3.4",
  "@angular/http": "~4.3.4",
  "@angular/platform-browser": "~4.3.4",
  "@angular/platform-browser-dynamic": "~4.3.4",
  "@angular/router": "~4.3.4",
  "core-js": "^2.4.1",
  "primeng": "^4.2.1",
  "rxjs": "^5.5.6",
  "zone.js": "^0.8.19"
},
"devDependencies": {
  "@angular/cli": "1.6.6",
  "@angular/compiler-cli": "^4.3.4",
  "@angular/language-service": "^4.3.4",
  "@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.1.0"
}

我的 module.ts 文件:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import {SidebarModule} from 'primeng/sidebar';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,SidebarModule,BrowserAnimationsModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

3 个答案:

答案 0 :(得分:0)

这可能是版本问题和版本不匹配

尝试制作

primeng:^4.2.4

答案 1 :(得分:0)

尝试再次执行此操作。

  

npm install primeng --save

     

npm install primeicons --save

并确保您的pack-lock.json具有此

"dependencies": {
  //...
  "primeng": "^7.0.0",
  "primeicons": "^1.0.0"
},

答案 2 :(得分:0)

我有类似的问题:

ERROR in ../node_modules/primeng/components/checkbox/checkbox.d.ts(1,49): error TS2307: Cannot find module '@angular/core'.
../node_modules/primeng/components/checkbox/checkbox.d.ts(2,51): error TS2307: Cannot find module '@angular/forms'.
../node_modules/primeng/components/listbox/listbox.d.ts(1,103): error TS2307: Cannot find module '@angular/core'.
../node_modules/primeng/components/listbox/listbox.d.ts(3,38): error TS2307: Cannot find module '@angular/forms'.

使用npm重新安装primeng解决了该问题