question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Constructor parameter in service is not compatible with dependency injection after build

See original GitHub issue

Type of Issue

[ X] Bug Report
[ ] Feature Request

Description

A bug: please describe the error that you encountered

In Angular 15 / ng-pckagr 15, after building and installing my library into another project, a service provided in my library reports:

The injectable EnvironmentService inherits its constructor from NgxEnvironmentService, but the latter has a constructor parameter that is not compatible with dependency injection. Either add an explicit constructor to EnvironmentService or change NgxEnvironmentService's constructor to use parameters that are valid for DI.(-992016)

However, when using the same service in test code within the library, everything works as expected

A feature: please describe your use case and motivation

I do not want developers leveraging my library to have to provide constructor arguments when extending this service class if they are not doing additional work in the constructor.

How To Reproduce

This is a private, scoped package, but I am more than happy to provide all source code.

To reproduce the issue, I build the library and install it into another Angular application using a local file path in package.json

Expected Behaviour

In all prior versions of this library, from Angular 11 - 14, everything works as expected. Updating from Angular/ng-packagr 14 to 15 builds and tests fine, but fails when implemented in another app.

Version Information

$ node_modules/.bin/ng-packagr --version
ng-packagr: 15.0.1
@angular/*: 15.0.0
typescript: 4.8.2
rxjs: 7.5.7
node: 18.12.0
npm/yarn: 8.19.2

Please include all version numbers that might be relevant, e.g. third-party libraries

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:17 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
JoostKcommented, Nov 24, 2022

If you’re curious: angular/angular#48156

0reactions
github-actions[bot]commented, Dec 25, 2022

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

This constructor is not compatible with Angular ...
Error: This constructor is not compatible with Angular Dependency Injection because its dependency at index 0 of the parameter list is invalid.
Read more >
Error :This constructor is not compatible with Angular ...
Uncaught (in promise): Error: This constructor is not compatible with Angular Dependency Injection because its dependency at index 2 of the ...
Read more >
this constructor was not compatible with dependency injection ...
ERROR: This constructor is not compatible with Angular Dependency Injection because its dependency at index X of the parameter list is invalid. This...
Read more >
Jest Service Inject Error after v12 upgrade #6097 - nrwl/nx
This constructor is not compatible with Angular Dependency Injection because its dependency at index 0 of the parameter list is invalid.
Read more >
Dependency injection in action
Supply a custom provider with @Inject link​​ The Inject decorator is a constructor parameter used to specify a custom provider of a dependency....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found