ng-packagr: Error during template compile of 'MyModule'

Type of Issue

Error when importing the compiled library

[x] Bug Report
[ ] Feature Request

Description

After running ng-packagr, I get the bundle and everything just fine, but when I’m going to import it in my Angular 5 App I get the error:

ERROR in Error during template compile of 'MyModule' Function calls are not supported in decorators in 'NgModule' 'NgModule' calls a function at @angular/core/core.ts(194,50).

I’m importing it like:

import { CountDownModule, CountDownComponent } from '../../../../projectLab/ng2-date-countdown'

@NgModule({
  declarations: [
    AppComponent,    
    CountDownComponent
  ],
  imports: [
    BrowserModule,
    CountDownModule,
  ],

How To Reproduce

Build an library with ng-packagr and import it in an Angular app.

Expected Behaviour

No errors

Version Information

ng-packagr: 2.0.0
@angular/*: x.y.z
typescript: x.y.z
rxjs: x.y.z
node: x.y.z
npm/yarn: x.y.z

please include any version information that might be relevant, e.g. other third-party libraries

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 9
  • Comments: 22 (4 by maintainers)

Most upvoted comments

@Gary-Pan You’re shipping dependencies and devDependencies with the @my/lib package. See https://github.com/Gary-Pan/my-lib/blob/master/package.json#L10-L44

@matheushf You’re shipping devDependencies with your library. The dist/package.json is:

{"name":"ng2-date-countdown","version":"0.0.5","description":"Angular2 Simple Date CountDown","main":"bundles/ng2-date-countdown.umd.js","module":"ng2-date-countdown.es5.js","typings":"ng2-date-countdown.d.ts","$schema":"./node_modules/ng-packagr/package.schema.json",
  "dependencies":{},
  "devDependencies":{
     "@angular/common":"5.1.2","@angular/compiler":"^5.1.2","@angular/compiler-cli":"^5.2.4","@angular/core":"5.1.2","@angular/platform-server":"^5.2.4","@ngtools/webpack":"^1.9.4","@types/core-js":"^0.9.43","@types/webpack":"^3.0.13","@types/webpack-env":"^1.13.0","angular2-template-loader":"^0.6.2","compression-webpack-plugin":"^1.1.6","copy-webpack-plugin":"^4.4.1","css-loader":"^0.28.9","extract-text-webpack-plugin":"^3.0.2","file-loader":"^1.1.6","gulp":"^3.9.1","gulp-inline-ng2-template":"^4.1.0","html-loader":"^0.5.5","html-webpack-plugin":"^2.30.1","json-loader":"^0.5.7","ng-packagr":"^1.7.0","node-sass":"^4.7.2","raw-loader":"^0.5.1","rxjs":"^5.5.6","sass-loader":"^6.0.6","to-string-loader":"^1.1.5","typescript":"^2.7.1","webpack-angular-externals":"^1.0.2","webpack-merge":"^4.1.1","webpack-rxjs-externals":"^1.1.0","zone.js":"^0.8.20"},"es2015":"ng2-date-countdown.js","metadata":"ng2-date-countdown.metadata.json"}

Hi everyone, I suspect my package is failing for the same reason.

The error stacktrace is simply:

ERROR in Error during template compile of 'NgxContentLoadingModule'
  Function calls are not supported in decorators in 'NgModule'
    'NgModule' calls a function at ../@angular/core/core.ts(194,31).

Not sure why, but my package returns no issues if I link it locally. 🤔

If anyone wants to take a look at the code, here is the package: https://github.com/Gbuomprisco/ngx-content-loading.

Thanks!