I'm having an issue loading an Angular 2 application after I've moved a few components from one module to another. My guess is that I'm doing something wrong in the code itself however the error I'm getting is not helpful and I don't know if it's an issue with Angular or Webpack.
Error when loading application:
Uncaught TypeError: Object prototype may only be an Object or null: undefined at setPrototypeOf (<anonymous>)
That is the error that I'm getting when the application is loaded. I know that the issue is somehow related to the services in the application but I'm not sure what is happening. This is where the application is failing:
What has caused the issue?
I have four modules within my application:
- AppModule
- CoreModule
- SharedModule
- FeatureModule
It is my aim to follow the Angular guidelines with regards to Modules. I had set the above listed modules a while ago and I noticed that I was using the CoreModule incorrectly. Apart from providing the services to be used in the application I had put "generic"/"reusable" components in this Module as well.
After reading the FAQs specifically about feature modules I set about moving these components to the SharedModule. Now most of these components make use of the services in the CoreModule. Once I moved these components to the SharedModule and updated the necessary code I began to encounter this issue.
Currently the modules I have are set up in the following way:
- AppModule imports the necessary modules along with the CoreModule and the FeatureModule
- CoreModule provides the services to be used in the application
- SharedModule declares and exports the generic components
- FeatureModule declares the components to be used in the specific feature
I'm not sure if I'm importing the wrong module in the wrong place, but I can't figure out why I'm getting this error simply because I moved a component from one module to another. I can't really understand the error which is making it difficult for me to understand what is wrong.
Setup versions:
- Angular: 4.0.1
- Webpack: 2.3.3
- TypeScript: 2.2.2
Further investigation
As mentioned above with the current setup I have most of the services being used across the whole application in one CoreModule (core folder). The components using these services are in a SharedModule (shared folder). When these components resided in the same module and folder everything was working as expected.
Now when I moved these components in the SharedModule, at first I was getting errors like what is described here but I had already encountered this before and I simply changed the import
s I have to reference the service directly instead of the barrel. Once I changed these imports I get the error shown above. Again I am lost as to what the problem is, I can't understand the error and the change I've done is that the components are moved to another folder and module to where the services reside. My suspicion is that somehow a circular dependency is created, but I'm not sure.