Cause: the issue is caused by "isolatedModules": true
flag in tsconfig.json.
Explanation:
when isolateModules
is set to true
, it applies some typescript restrictions to ensure that each file can be independently transpiled. This flag prevents typescript from doing the full code analysis needed to generate metadata for tree-shaking and causes all @Injectable()
services to be included in the result bundle. It's because the compiler cannot tell whether the service is used or not.
Fix:
remove isolateModules
from tsconfig.json or set it to false.