angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Library (ng-packagr) - 'NgModule' calls 'ɵmakeDecorator'

Open ErazerBrecht opened this issue 8 years ago • 18 comments

Versions

Angular CLI: 6.0.1
NodeJS: 9.9.0
OS: Win10 x64

Repro steps

  • Create a library (ng generate library my-lib)
  • Use the library
  • Build for production (ng build --prod)

Repository where you can reproduce the bug

  • npm run serve:all works (dev version)
  • npm run build works (non-production build)
  • npm run release doesn't work (production build)

Observed behavior

ERROR in ..\Library\dist\Auth\auth.ts(4,2): Error during template compile of 'AuthModule'
Function calls are not supported in decorators but 'ɵmakeDecorator' was called in 'NgModule'
'NgModule' calls 'ɵmakeDecorator'.

Desired behavior

That an AOT build works

Mention any other details that might be useful (optional)

Already reported @ ngpackagr: https://github.com/dherges/ng-packagr/issues/727 But I'd like to have an issue at 'CLI level' so I (and probably other people as well) can keep track of it.

At the moment I also don't know where it's broken. Is it ng-packagr is it angular, or am I missing documentation somewhere.

Sincerely, Brecht Thx for your time

ErazerBrecht avatar May 14 '18 06:05 ErazerBrecht

I'm getting the same error only when importing Shared Library's module into another Feature Library's module.

BUILD ERROR
Error during template compile of 'NgModule'
  Function calls are not supported in decorators but 'ɵmakeDecorator' was called.
: Unexpected value 'SharedModule in c:/Development/Solar-Log/core-ui-v1/enerest/dist/shared/solar-log-shared.d.ts' imported by the module 'AdministrationModule in C:/Development/Solar-Log/core-ui-v1/enerest/projects/administration/src/lib/administration.module.ts'. Please add a @NgModule annotation.

I tried the fix from this post. this error disappeared but now I'm getting

BUILD ERROR
Cannot read property 'type' of null
TypeError: Cannot read property 'type' of null
    at C:\Development\Solar-Log\core-ui-v1\enerest\node_modules\@angular\compiler\bundles\compiler.umd.js:15481:31
    at Array.forEach (<anonymous>)
    at ...

I've found this post but the solution is not working.

What do you guys think? Is it better to link libraries into each other or pass shared data from main project via forRoot methods?

GeorgeKnap avatar Aug 24 '18 09:08 GeorgeKnap

Did anyone got solution for this issue me to getting same issue using ng packagr version 3.0.0

srinivasganaparthi avatar Oct 02 '18 01:10 srinivasganaparthi

Running into the same issue right now, any help?

FanFanFantastic avatar Nov 13 '18 17:11 FanFanFantastic

@GeorgeKnap have you looked at the update on the second post you linked to?

It looks like there might be the solution - https://github.com/angular/angular/issues/24143#issuecomment-422755085

shairez avatar Nov 28 '18 13:11 shairez

@shairez In a way yes, this comment is correct. Anyway, modifying tsconfig's paths was necessary to make ng serve work with libraries.

Honestly I'm not sure whether this fixed my issue above or some angular updates, but I'm not getting these problems anymore.

GeorgeKnap avatar Nov 28 '18 13:11 GeorgeKnap

Yep, that was my experience too @GeorgeKnap

The paths trick did the trick 😄

shairez avatar Dec 02 '18 20:12 shairez

Hi @shairez, what you specified in the paths section. I guess you are talking about tsconfig.app.json. Thanks!

rahulsahay19 avatar Dec 09 '18 08:12 rahulsahay19

@rahulsahay19 Yeah, in tsconfig.app.json I ended up configuring:

"paths": {
      "@angular/*": ["../node_modules/@angular/*"],
      "@ng-bootstrap/*": ["../node_modules/@ng-bootstrap/*"],
      "ngx-bootstrap": ["../node_modules/ngx-bootstrap"],
      "ngx-bootstrap/*": ["../node_modules/ngx-bootstrap/*"]
    }

And that did the trick

shairez avatar Dec 10 '18 00:12 shairez

@shairez

Thanks for the response. Sorry about late reply. However, I found in my case, its not fixing the problem. Even after doing the suggested steps, its still giving the same issue!

Thanks, Rahul

rahulsahay19 avatar Dec 17 '18 07:12 rahulsahay19

Closing this issue since it's a compiler problem https://github.com/angular/angular/issues/23609

mgechev avatar Dec 17 '18 21:12 mgechev

Here is my problem . I have created separate project and building that with ng-packagr .Using npm link I am trying to access the build folder to my current project node_module component

getting this as error in my current project

ERROR in ../ui-components/index.ts(14,2): Error during template compile of 'LoginModule' Function calls are not supported in decorators but 'ɵmakeDecorator' was called in 'NgModule' 'NgModule' calls 'ɵmakeDecorator'. node_modules/@angular/core/src/render3/ng_dev_mode.d.ts(9,11): error TS2451: Cannot redeclare block-scoped variable 'ngDevMode'. node_modules/ui-components/node_modules/@angular/core/src/render3/ng_dev_mode.d.ts(9,11): error TS2451: Cannot redeclare block-scoped variable 'ngDevMode'.

Let me know how to resolve this

secabhi avatar Mar 29 '19 12:03 secabhi

@secabhi same problem with npm link

chikakow avatar Apr 29 '19 18:04 chikakow

@secabhi If you are using npm link to link your other library in current library project, then referencing its path from node_modules folder in the paths array of tsconfig.json should work.

sosspyker avatar May 10 '19 17:05 sosspyker

I confirmed that the issue has to do with "link:../yourPath/" in my project (thank you @sosspyker and @chikakow). I switched it to "file:../yourPath/" as a quick workaround. But does anyone know how to resolve this issue?

egdraper avatar May 23 '19 19:05 egdraper

As @rahulsahay19 suggests, adding

"paths": {
      "@angular/*": ["../node_modules/@angular/*"]
}

to my tsconfig.json did the trick.

austinwk avatar Jul 24 '19 21:07 austinwk

ERROR in ..\path_to.component.ts(3,2): Error during template compile of 'XX' Function calls are not supported in decorators but 'ɵmakeDecorator' was called in 'Component' 'Component' calls 'ɵmakeDecorator'.

This is because during the build of

ng-build --prod

the compiler finds the wrong import paths to the components somewhere in the application. Find and delete unused and incorrect imports.

addsmoll avatar Aug 30 '19 10:08 addsmoll

Hi all,

not sure if this helps but I got here searching google for.

Function calls are not supported in decorators but 'ɵmakeDecorator' was called in 'Injectable'              
    'Injectable' calls 'ɵmakeDecorator'.

After seeing path issues mentioned in this thread I searched for anything being referenced outsite of the project space and found this import...

src/app/tour/tour.actions.ts:import {SomeEntity} from "../../../../fe/src/app/model";

This import (a mistake in my code) was fixed to reference the model in the project it belonged to.

import {SomeEntity} from '../model';

Once the import was fixed I had a successful compile. The error output was no help, this thread was, so here is my pennies worth.

peter-snr avatar Sep 29 '19 18:09 peter-snr

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.