Fix: Resolve Runtime Issue with Enums in Angular Build Optimization
oliverseges opened this issue · comments
Hi Alexander,
I've identified and addressed a runtime issue that emerged after executing build optimization in our Angular project. This issue pertains to unrecognized enums in the optimized build.
Pull Request: #13
Technical Details:
The core change involves transitioning enums to const enums. This modification enhances compatibility with Angular's optimized build process.
A point to consider: This alteration impacts the conventional enumeration iteration. For any existing code that iterates through enums, a refactoring would be necessary.
As a workaround, I suggest creating an explicit array of enum values. This approach maintains iteration functionality while ensuring compatibility with the optimized build.
Impact Analysis:
This change is crucial for the stability and performance of our Angular application in production environments.
Teams should review any existing enum iterations in their code and apply the suggested workaround where necessary.
Please review the changes and let me know if there are any concerns or additional modifications required.
@oliverseges I think that the root of this issue is a change of enums compilation method that happened somewhere between Typescript 4 and Typescript 5. Here is a corresponding issue in Angular repo, but it was fixed only in the latest version of Angular, not in Angular 14.
I think that the right solution would be to provide both CommonJS and ESModule imports - as I understand, Angular is happy to use ESModules instead of CommonJS. Here is a PR - I tried it locally with Angular 14 and it works for me.
Could you test it with your project, please?
@aparshin I'll test it later today and let you know how it goes. I agree that it should likely fix the issue too.
@aparshin, sorry for my delayed reply!
I've managed to compile the library from the pull request and incorporate it into the node modules folder. Post-build optimization, it's working seamlessly, with dist_es. I have closed my pull request now, as this method seems more efficient for both Angular and non-Angular developers.
(I did have to build the library for the dist_es folder to appear. Importing from the branch did not work.)
I really appreciate your prompt responses and the effort you've put into this library. It's been incredibly helpful. Thank you! 👍
@oliverseges I glad that it works for you! I published v1.9.5 with this fix to npm registry.
Thank you for reporting this problem! And let me know if you have some other issues.
@oliverseges I glad that it works for you! I published v1.9.5 with this fix to npm registry.
Thank you for reporting this problem! And let me know if you have some other issues.
@aparshin The npm package only seems to contain the dist folder. Is it lacking the new build?
@oliverseges my mistake - forgot to include new folder in the package. Also, excluded tests from package to minimise its size a little bit. Please test v1.9.6.
@oliverseges my mistake - forgot to include new folder in the package. Also, excluded tests from package to minimise its size a little bit. Please test v1.9.6.
@aparshin I'm unfortunately on vacation, so I won't be able to test it for at least a week, but it looks good now 👍 I don't foresee any issues.