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.

ModuleWithProviders is not generic error

See original GitHub issue

I have an Angular 5-based module (5.2 to be precise) and when I use the latest version (6.2.0) I get the following error message during the test run:

$ yarn test
yarn run v1.7.0
$ ng test
 10% building modules 1/1 modules 0 active16 10 2018 13:38:59.629:WARN [karma]: No captured browser, open http://localhost:9876/
16 10 2018 13:38:59.643:INFO [karma]: Karma v3.0.0 server started at http://0.0.0.0:9876/
16 10 2018 13:38:59.645:INFO [launcher]: Launching browser ChromeHeadless with unlimited concurrency
16 10 2018 13:38:59.651:INFO [launcher]: Starting browser ChromeHeadless
[./src/polyfills.ts] ./src/polyfills.ts 0 bytes {polyfills} [built]
   [0] multi ./src/polyfills.ts 28 bytes {polyfills} [built]
[./src/test.ts] ./src/test.ts 0 bytes {main} [built]


ERROR in node_modules/shallow-render/dist/lib/models/test-setup.d.ts(9,50): error TS2315: Type 'ModuleWithProviders' is not generic.
node_modules/shallow-render/dist/lib/models/test-setup.d.ts(9,88): error TS2315: Type 'ModuleWithProviders' is not generic.

If I edit the test-setup.d.ts file at line 9 and change it (removing the <any> following ModuleWithProviders):

readonly moduleReplacements: Map<Type<any> | ModuleWithProviders, Type<any> | ModuleWithProviders>;

compilation now completes. I tried stepping back to v6.1.3 but the error still occurred.

Is there a version I could use so that I didn’t have to manually edit the file (worried about deploying this to my co-workers so they can start writing tests using the shallow-render package).

I’m just forging into the world of testing frontend code involving Angular. Happy to provide additional info if I haven’t provide sufficient details. Trying to get testing to work first then consider migrations to Angular 6 and beyond if possible.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Pinka30commented, May 5, 2020

Thanks a lot. You spotted the exact issue. @angular/core had version without ^ sign and other two did not. I removed ^ from other two and did npm i. It’s working. 😃

1reaction
getsafcommented, May 5, 2020

I don’t think this is a shallow-render issue. In the error stack you posted the error is coming from @angular/router and @angular/platform-browser. My guess is that somehow your angular libraries are on mis-matched versions.

I would try running: npm ls @angular/core @angular/router @angular/platform-browser

and make sure they all match up to be the same versions.

For sanity, I just created an Angular 6.1 project and installed shallow-render@7 and everything worked fine. Here’s my project for reference: https://github.com/getsaf/ng6-shallow-render

Read more comments on GitHub >

github_iconTop Results From Across the Web

ANGULAR 6: error TS2315: Type 'ModuleWithProviders' is not ...
ANGULAR 6: error TS2315: Type 'ModuleWithProviders' is not generic · From the look at the error it looks that the definition for the ......
Read more >
Type 'ModuleWithProviders' is not generic - ionic-v3
Typescript is going me crazy: these are the errors all related to firebase, command is ionic cordova run android
Read more >
ModuleWithProviders Migration - Angular
Angular version 9 deprecates use of ModuleWithProviders without an explicitly generic type, where the generic type refers to the type of the NgModule...
Read more >
generic type 'modulewithproviders<t>' requires 1 type argument
this error tells you that, the ModuleWithProviders class has 1 generic paramter. so you sould use it like ModuleWithProviders<T> where T is a...
Read more >
ModuleWithProviders MDB angular error - MDBootstrap
Expected behavior. On upgrade to Angular 9 ModuleWithProviders now requires a generic type argument. That causes an error. Actual behavior.
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