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.

jest: doesn't seem to work with compilerOptions.paths option

See original GitHub issue

According to this article, I have the following In my tsconfig.json: projects/core/tsconfig.spec.json

{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "outDir": "../../out-tsc/spec",
    "module": "commonjs",
    "types": [
      "jest",
      "node"
    ],
    "allowJs": true,
  },
  "files": [
    "../../test.ts"
  ],
  "include": [
    "**/*.spec.ts",
    "**/*.d.ts"
  ]
}

tsconfig.spec.json // notice the paths

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "types": ["jest"],
    "lib": [
      "es2017",
      "esnext.asynciterable",
      "dom"
    ],
    "paths": {
      "@pwa/*": ["projects/pwa/src/app/*"],
      "@mobile/*": ["projects/mobile/src/app/*"],
      "@core/*": ["projects/core/src/*"],
      "@auth/*": ["projects/auth/src/*"]
    }
  }
}

the .spec file has an import like this:

import { something } from '@core/some.service';

This results in an error:

Cannot find module ‘@core/some.service’ from ‘some.service.spec.ts’

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
just-jebcommented, Aug 28, 2018

Yep, this is actually Jest’s problem. It doesn’t read the tsconfig.json neither does ts-jest . In fact, jest uses a bit different syntax for mappings. Check out this example, you have to add your mappings to your jest config under moduleNameMapper.

0reactions
just-jebcommented, Nov 2, 2018

Not angular-builders issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript paths not resolving when running jest?
I wanted to resolve modules paths starting with ~/ to my <baseUrl>/<moduleName> . Thank to OJ Kwon link I solved it with (give...
Read more >
Paths mapping | ts-jest - GitHub Pages
ts-jest provides a helper to transform the mapping from tsconfig to Jest config format, but it needs the . js version of the...
Read more >
TSConfig Reference - Docs on every TSConfig option
All relative paths found in the configuration file will be resolved relative to the configuration file they originated in. It's worth noting that...
Read more >
Typescript — How to solve the problem with unresolved path ...
This seems working OK in most of the cases, if all your source files and sub-folders are located under the same rootDir.
Read more >
Typescript does not resolve modules through tsconfig.json's ...
So,it doesn't use settings in your tsconfig.json when compiling your files, it uses default TS options instead.
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