After recently updating angular apollo from version 2.6.0 to v3.0.0, my tests have been broken.
I use jest for unit testing, and although the application compiles and runs without any issues, my tests cannot import any dependencies from 'apollo-angular'. This results in errors like the following:
Test suite failed to run
Cannot find module 'apollo-angular' from 'src/graphql/generated/graphql.ts'
Require stack:
src/graphql/generated/graphql.ts
src/app/pages/test/test.component.ts
src/app/pages/test/test.component.spec.ts
1 | /* eslint-disable */
> 2 | import { gql } from 'apollo-angular';
| ^
3 | import { Injectable } from '@angular/core';
4 | import * as Apollo from 'apollo-angular';
5 | export type Maybe<T> = T | null;
at Resolver.resolveModule (node_modules/jest-resolve/build/resolver.js:324:11)
at Object.<anonymous> (src/graphql/generated/graphql.ts:2:1)
The module resolution process follows a specific order, and due to 'apollo-angular' v3 using .mjs
, the resolved file is typically package.json
(located at
node_modules/apollo-angular/package.json</code). This <a href="https://github.com/kamilkisiela/apollo-angular/blob/master/packages/apollo-angular/package.json#L15" rel="nofollow noreferrer">package.json</a> includes the 'module' property stating:</p>
<pre class="lang-json"><code>{
"module": "build/fesm2020/ngApollo.mjs"
}
To clarify, when importing
import * as Apollo from 'apollo-angular'
, I expect jest to resolve to node_modules/apollo-angular/package.json
, which should point to build/fesm2020/ngApollo.mjs
- the intended file for import.
While TypeScript successfully compiles the project and can import this ES module, Jest is unable to do so. What could I possibly be overlooking?