I am struggling with the NG0203 error, while my colleagues are able to serve the project without any problem. I tried to upgrade and downgrade the versions of both Angular and Nx, but it did not work. Also, I tried to copy the entirety of the node_modules from one of my teammates, but still had no luck.I don't think it's related but I also checked the ports where i need to serve the apps on.
Error: NG0203: inject() must be called from an injection context such as a constructor, a factory function, a field initializer, or a function used with runInInjectionContext. Find more at https://angular.io/errors/NG0203
i have several angular applications with different versions and i dont experience any trouble with them thanks to NVM. Does anyone know what could be the root cause of this?
nx version 17.2 ng version 16.2 macOS 13.6.3 (22G436) - intel
i do make it sure that my project and packages are exactly same with my teammates. these all findings make the thing more mysterious to me.
i tried to downgrade and upgrade the nx and ng versions. also tried serve the project on node 16 and 18 versions. also checked several browsers.
i was able to serve the project on windows via node v18.19, then also tried to test this on another mac 2016 but it did not work either.
as so far it should be highlighted to you that this error arise when the inject() function is called outside of the allowed injection contexts.
so inject() function can be called within the constructor of a class to inject dependencies.
also check for any configuration issues in the project's
angular.jsonfile or any other relevant configuration filesplease take a look at NG0203
as you highlighted that the sane code with the exactly same configration is working fine to others .so try the following trick and see if works.