Angular-cli + primeng require is not defined

人走茶凉 提交于 2019-12-08 03:33:22

问题


I'm using angular-cli@1.0.0-beta.14 (webpack) and primeng@1.0.0-beta.15.

After create a fresh angular-cli project i made a few changes to add primeng:

1 on package.json:

"primeng": "^1.0.0-beta.15"

2 on angular-cli.json:

"styles": [ "styles.css", "../node_modules/primeng/resources/themes/omega/theme.css", "../node_modules/font-awesome/css/font-awesome.min.css", "../node_modules/primeng/resources/primeng.min.css" ],
"scripts": [ "../node_modules/primeng/primeng.js" ]

3 on app.module.ts:

@NgModule({ declarations: [ AppComponent ],
imports: [ BrowserModule, FormsModule, HttpModule, PanelModule ],
providers: [], bootstrap: [AppComponent] }) export class AppModule { }

Problem:

Uncaught ReferenceError: require is not defined Unexpected value 'undefined' imported by the module 'AppModule'

Any help to add primeng to angular-cli... will we great! :)


回答1:


So just about everything you have there looks good.

The issue lies in that you're attempting to include primeng as a script tag (which is for global libraries like jQuery). But since primeng deploys modules you can simply import it in your module and then supply that to your NgModule like this:

import { ButtonModule } from 'primeng/components/button/button';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    ButtonModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

And then you'll also want to remove the reference to primeng.js from your angular-cli.json



来源:https://stackoverflow.com/questions/39514408/angular-cli-primeng-require-is-not-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!