ng-chartist: ERROR in ChartistModule is not an NgModule

OS?

Mac OSX El Capitan - 10.11.6 (15G1004)

Versions.

@angular/cli: 1.0.0-beta.32.3
node: 6.9.5
os: darwin x64
@angular/common: 2.4.0
@angular/compiler: 2.4.0
@angular/core: 2.4.0
@angular/forms: 2.4.0
@angular/http: 2.4.0
@angular/platform-browser: 2.4.0
@angular/platform-browser-dynamic: 2.4.0
@angular/router: 3.4.0
@angular/cli: 1.0.0-beta.32.3
@angular/compiler-cli: 2.4.0

Chartists Versions

angular2-chartist: 0.12.1
chartist": ^0.10.1
@types/chartist: ^0.9.34

I use angular/cli and when use the command ng serve returned this error ERROR in ChartistModule is not an NgModule but, when change and save any file, livereload omitted the error and all ok.

the main problem is in production mode. when i tried use the command ng build got this

ERROR in Unexpected value 'ChartistModule in /Users/userName/mainFolder/Project/tablero/node_modules/angular2-chartist/dist/chartist.component.d.ts' imported by
the module 'AppModule in /Users/userName/mainFolder/Project/tablero/src/app/app.module.ts'

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/Users/userName/mainFolder/Project/src'
 @ ./src/main.ts 4:0-74
 @ multi ./src/main.ts

anyone can help me?. i don’t know how solve this.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 25 (4 by maintainers)

Most upvoted comments

I suggest using: ng build --env=prod --output-hashing none and works fine

If anyone comes here looking for solution; I found that it works if you import from src, but not if you import from dist

import { ChartistModule } from "ng-chartist/src/chartist.component"

Fixed the “ChartistModule is not an NgModule” error for me

ng build --prod --aot=false

works for me!

I tried with version 0.12.2 and is the same problem and same solution. Nothing change.

ERROR in ChartistModule is not an NgModule with ng serve

ERROR in Unexpected value 'ChartistModule in /Users/Nico/Desktop/tableroKpi/node_modules/angular2-chartist/dist/chartist.component.d.ts' imported
by the module 'AppModule in /Users/Nico/Desktop/tableroKpi/src/app/app.module.ts'

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/Users/Nico/Desktop/tableroKpi/src'
 @ ./src/main.ts 4:0-74
 @ multi ./src/main.ts

with ng build --prod and ng build --prod --aot

I found solution. I tested with other packages and compared to angular2-chartist I found 1 difference.

Angular-cli ver. 1.0.0-beta.32.3

Is necessary edit tsconfig.json.

see a example.

                  ...
    "module": "es2015",
    "moduleResolution": "node",
    "paths": {
      "angular2-chartist": [
        "../node_modules/angular2-chartist/src"
      ]
    },
    "outDir": "../dist/out-tsc",
    "sourceMap": true,
                ....

we need to add this.

    "paths": {
      "angular2-chartist": [
        "../node_modules/angular2-chartist/src"
      ]
    },

Next, it is necessary edit the angular2-chartist package.

  • i tried with other packages and the solution works without edit.

First go to src directory. ./node_modules/angular2-chartist/src

Next create new file. named index.ts and add next line code in file.

export * from './chartist.component';

And everything works fine. No errors.