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.

How to use with target="es6"?

See original GitHub issue

I use https://github.com/s-panferov/awesome-typescript-loader instead of ts-loader, which speeds up compilation. My current tsconfig.json is:

{
  "compilerOptions": {
    "noEmit": true,
    "target": "es6",
    "module": "commonjs",
    "moduleResolution": "node",
    "jsx": "preserve",
    "lib": ["dom","es5","es6","es7","es2017.object"]
  },
  "filesGlob": [
    "./**/*.ts"
  ],
  "exclude": [
    "node_modules",
    "build"
  ],
  "awesomeTypescriptLoaderOptions": {
    "useBabel": true,
    "forkChecker": true,
    "useCache": false
  }
}

And my jest config is:

  "jest": {
    "collectCoverageFrom": [
      "app/**/*.{js,jsx}",
      "!app/app.js",
      "!app/routes.js"
    ],
    "moduleDirectories": [
      "node_modules",
      "<rootDir>/app"
    ],
    "moduleNameMapper": {
      ".*\\.css$": "<rootDir>/mocks/cssModule.js",
      ".*\\.jpg$": "<rootDir>/mocks/image.js",
      ".*\\.svg$": "<rootDir>/mocks/svg.js"
    },
    "setupTestFrameworkScriptFile": "<rootDir>/internals/testing/test-bundler.js",
    "testRegex": "tests/.*\\.test\\.(ts|tsx|js)$",
    "transform": {
      ".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
    },
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js",
      "json"
    ]
  }

So my tests obviously fail with SyntaxError: Unexpected token import. How to handle this setup with ts-jest?

node: v.6.6.0 typescript: 2.0.8 ts-jest: 17.0.0

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
niedzielskicommented, Apr 16, 2017

@kulshekhar, sorry for the late response. The import issue appeared at the time to come from a missing transform field in my config. The transform issue was difficult to track down because I appeared to be seeing a new issue that when the config changed, either through a different file via--config or when a consistently named config file itself changed, that the cache didn’t invalidate. I had planned to report the caching config issue as a standalone bug but unfortunately I can no longer reproduce it. For now, I apologize for the noise and will file a ticket if I can reproduce it again.

1reaction
niedzielskicommented, Apr 13, 2017

First time user here. I seemed to have had a similar (?) issue with imports when I accidentally mangled my Jest config to omit transform. What really bit was me that the cache doesn’t invalidate when the config changes. You can really test your config by disabling it, jest --no-cache. You can check out the recommended example config here. I found the import token error quite cryptic.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TSConfig Option: target - TypeScript
Modern browsers support all ES6 features, so ES6 is a good choice. You might choose to set a lower target if your code...
Read more >
What is target in tsconfig.json for? - Stack Overflow
Changing your target means changing the libraries with which your code compiles. If you want to keep the target a low version while...
Read more >
Easy TypeScript: A Quick Guide to the target Option
The target option is configurable in your tsconfig.json or on the command-line via the --target flag. It refers to the JavaScript target that...
Read more >
Typescript - selecting proper target version - Dancing with CRM
Learn why you should choose proper target version in your tsconfig file and how it boost your code.
Read more >
ES6 Tutorial For Beginners - function.name and new.target
ES6 Tutorial For Beginners - function.name and new. target ... Make Obstacles And Restricted Areas In A Map Using Navigation Meshes ...
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