ts-jest: Sourcemaps do not work

Thanks for the nice package. I have issues making sourcemaps work. I have tried adding --no-cache but I’m still getting error lines of transpiled source (or did I miss anything that console errors should be mapped to correct line?)

Here is my package.json

{
  "scripts": {
    "test": "jest --no-cache",
  },
  ...
  "jest": {
     "globals": {
      "__TS_CONFIG__": "tsconfig.test.json"
    },
    "moduleNameMapper": {
      "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/.storybook/__mocks__/fileMock.js",
      "\\.(css|less)$": "<rootDir>/.storybook/__mocks__/styleMock.js"
    },
    "setupFiles": [
      "<rootDir>/jest.startup.js"
    ],
    "transform": {
      ".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
    },
    "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js"
    ],
    "snapshotSerializers": [
      "<rootDir>/node_modules/enzyme-to-json/serializer"
    ]
  }
}

And here is the tsconfig.test.json

{
    "compileOnSave": false,
    "compilerOptions": {
        "allowSyntheticDefaultImports": true,
        "lib": [
            "dom",
            "es2015",
            "es2016"
        ],
        "noEmitHelpers": false,
        "emitDecoratorMetadata": true,
        "jsx": "react",
        "target": "es2016",
        "module": "commonjs",
        "moduleResolution": "node",
        "removeComments": true,
        "preserveConstEnums": true,
        "sourceMap": true,
        "strictNullChecks": false,
        "noImplicitReturns": true,
        "noImplicitThis": true,
        "noUnusedLocals": false,
        "noUnusedParameters": true,
        "skipLibCheck": true,
        "skipDefaultLibCheck": true,
        "experimentalDecorators": true,
        "outDir": "./build",
        "types": [
            "chai",
            "react"
        ],
        "typeRoots": [
            "src/typings/overrides",
            "node_modules/@types"
        ],
        "pretty": true
    },
    "exclude": [
        "node_modules"
    ]
}

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 2
  • Comments: 17 (9 by maintainers)

Most upvoted comments

I was also struggling with broken sourcemaps, but disabling coverage made them work! I’m using Jest 24.5.0. I just changed my debug script to add --coverage=false and sourcemaps started working.

sourcemaps are not working for me as well…

@kulshekhar

there are tests in the repo that can help understand how to use ts-jest

Tests are not user friendly, examples are.

See PR #118

(this is the first thing that comes up on Google)

This is a bug within Jest regarding coverage breaking source maps:

https://github.com/facebook/jest/issues/5739

@kulshekhar Thanks! I will do that!

@villelahdenvuo this is exactly why i love JS 😃

can you create a minimal repo that reproduces the issue you’re facing?