On the Gitlab-CI environment 2 of our Jest tests fail with Cannot find module
.
The strange thing is that it works on my local Win10 machine - even when I run the tests in a similar docker-container (node 12.12.0
).
Here is the console output:
FAIL apps/server/src/domain/dashboard/permission-group.service.spec.ts
Test suite failed to run
Cannot find module '@cm/utils-server' from 'license.service.ts'
9 | isLicenseFileContent,
10 | LicenseStatus,
> 11 | parseLicenseInfo
| ^
12 | } from '@cm/license-shared';
13 | import { ExitCode } from '../../util/exit-codes';
14 | import { readFile } from '@cm/utils-server';
at Resolver.resolveModule (../../node_modules/jest-resolve/build/index.js:259:17)
at Object.<anonymous> (src/domain/license/license.service.ts:11:24)
I am not sure how to correctly interpret this output:
permission-group.service.spec.ts
: this is the test that failsCannot find module '@cm/utils-server' from 'license.service.ts'
:
Ok, the test or some of its dependencies, uselicense.service.ts
and in thelicense.service.ts
file the'@cm/utils-server'
module cannot be found.- What is the meaning of error-indicator (
>
atparseLicenseInfo
)?- This is for the import
@cm/license-shared
- not for@cm/utils-server
as indicated by the error message in 2 @cm/utils-server
is also imported, but 2 lines below in line 14: So is this maybe just a bug in jest?
- This is for the import
paths
defined in multipletsconfig.json
files of our mono-repo. We moved all paths up to the root-tsconfig and now the tests work again. But we don't really understand why this works. And this has the drawback that it is now easy to accicentially refer to a path that you shouldn't use in the lib (because the IDE now always uses all paths for code-assistance) – Monumental