Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

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

Open
kmturley opened this issue Oct 31, 2018 · 4 comments
Open

Comments

@kmturley
Copy link

[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

@fknop
Copy link
Owner

fknop commented Oct 31, 2018

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 ?

@kmturley
Copy link
Author

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 :|

@fknop
Copy link
Owner

fknop commented Nov 1, 2018

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

@kmturley
Copy link
Author

kmturley commented Nov 1, 2018

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants