ModuleWithProviders is not generic error
See original GitHub issueI 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:
- Created 5 years ago
- Comments:13 (6 by maintainers)
Top GitHub Comments
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 didnpm i
. It’s working. 😃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