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-babel createTransformer Error: customJSTransformer.includes is not a function

See original GitHub issue

🐛 Bug Report

When using the transform configuration, for transpiling my JS using Babel, I get an error from jest stating:

TypeError: customJSTransformer.includes is not a function

This error occurs, since the setupBabelJest assumes, that the JS transform property is an array: https://github.com/facebook/jest/blob/master/packages/jest-config/src/normalize.js#L138 But the value returned by babelJest.createTransformer() is an Object with implements the Jest Transformer. I’m not shure how a fix might be possible, otherwhise I would include a PR. Maybe the if chain could first check, if it an Object and then else if () check if it’s an array afterwards.

To Reproduce

jest.config.js:

const babelJest = require("babel-jest");

module.exports = {
  transform: {
    "^.+\\.jsx?$": babelJest.createTransformer({
      presets: [
        [
          require.resolve("babel-preset-env"),
          {
            targets: {
              node: "10"
            }
          }
        ]
      ]
    })
  }
};

command: jest

Expected behavior

The transformer should be appended correctly and without error to the jest Config

Link to repl or repo (highly encouraged)

https://github.com/NicolaiSchmid/jest-error

  • clone
  • yarn
  • yarn test

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: Linux 4.15 Ubuntu 18.04.1 LTS (Bionic Beaver)
    CPU: x64 Intel(R) Core(TM) i5-4430 CPU @ 3.00GHz
  Binaries:
    Node: 9.4.0 - ~/.nvm/versions/node/v9.4.0/bin/node
    Yarn: 1.9.4 - /usr/bin/yarn
    npm: 6.3.0 - ~/.nvm/versions/node/v9.4.0/bin/npm

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:8

github_iconTop GitHub Comments

3reactions
SimenBcommented, Sep 20, 2018

We do not have support for creating a transformer that way. It needs to be a separate file, then you can do require.resolve on it.

I do think supporting it would be good though, so keeping this open as a feature request

2reactions
vxcamiloxvcommented, Nov 29, 2018

I have a similar error but with Array.reverse is not a function I tried with a custom transform, and with the babel.config.js on the root of the package (sub-package on monorepo) and didn’t work, I also tested passing directly the configuration options to the transformer and didn’t work.

module.exports = babelJest.createTransformer({
  rootMode: 'upward',
});
  "jest": {
    "transform": {
      "^.+\\.js$": "<rootDir>/config/babelJest.js"
    }
   }
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use the babel-jest.createTransformer function in ... - Snyk
To help you get started, we've selected a few babel-jest examples, based on popular ways it is used in public projects. Secure your...
Read more >
babelrcを使わずに独自のBabelの設定を使ってJestを実行する
Jest-babel createTransformer Error: customJSTransformer.includes is not a function · Issue #7015 · facebook/jest · GitHub.
Read more >
Updating CRA from version 4 to version 5 breaking babel-jest
When running npm test I see the following error: Determining test suites to run. ... createTransformer is not a function at Object.
Read more >
巴别塔笑话, 插件/预设文件不允许导出对象,只有函数babel-preset ...
这里报错是因为babel的Error: Plugin/Preset files are not allowed to export objects, ... Jest-babel createTransformer 错误:customJSTransformer.includes.
Read more >
cannot read properties of undefined jasmine - You.com
The directive has a controller, which has functions, which use global ... 23 to Jest/Babel-Jest 24. updated my custom JS transformer to use...
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