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

Angular Universal + Lazy Modules build error (declarations of 2 modules)

Open kmturley opened this issue 7 years ago • 4 comments

[x] bug report
[ ] feature request

Current behavior When loading a lazy module, which imports SlugifyPipe directly. Then the app.module.ts imports a Shared Module with SlugifyPipe exported. It runs fine in the browser using ng serve, but when running ng build --prod it fails with the error:

ERROR in : Type SlugifyPipe in angular-pipes.d.ts is part of the declarations of 2 modules: SharedModule in shared.module.ts and NgStringPipesModule in angular-pipes.d.ts! Please consider moving SlugifyPipe in angular-pipes.d.ts to a higher module that imports SharedModule in shared.module.ts and NgStringPipesModule in angular-pipes.d.ts. You can also create a new NgModule that exports and includes SlugifyPipe in angular-pipes.d.ts then import that NgModule in SharedModule in shared.module.ts and NgStringPipesModule in angular-pipes.d.ts.

Expected behavior ng build --prod to compile

Minimal reproduction of the problem with instructions Check out my example project for the source code i'm using: https://github.com/kmturley/angular-google-sheets/blob/master/src/app/app.module.ts#L10 https://github.com/kmturley/angular-google-sheets/blob/master/src/app/shared/shared.module.ts

What is the motivation / use case for changing the behavior? I believe it's a bug, Angular Universal static generation is stricter than normal runtime and it checks for duplicate imports

kmturley avatar Oct 31 '18 19:10 kmturley

Hello, I don't really know how Universal works. But are you sure that putting a pipe in providers https://github.com/kmturley/angular-google-sheets/blob/master/src/app/shared/shared.module.ts#L18 is the correct way to do it ?

fknop avatar Oct 31 '18 20:10 fknop

I swapped out your plugin for this version: https://gist.github.com/djabif/b8d21c4ebcef51db7a4a28ecf3d41846

and the same code works... I believe it's because you are also exporting it as a Module, it fails the build because their are two modules :|

kmturley avatar Oct 31 '18 21:10 kmturley

It seems weird considering you never import NgStringPipesModule, I'll try to look into Universal to see if there is any issues regarding this.

fknop avatar Nov 01 '18 09:11 fknop

Yeah it works fine in the browser, it's just when running a production static build with universal. I've noticed that it's stricter than the regular compiler. Sometimes throwing up other issues too.

kmturley avatar Nov 01 '18 12:11 kmturley