Jest: Jest-babel createTransformer Error: customJSTransformer.includes is not a function

Created on 20 Sep 2018  路  5Comments  路  Source: facebook/jest

馃悰 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
Feature Request Help Wanted

Most helpful comment

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

All 5 comments

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

Should I do a PR for it? I could free up some time in the coming week.

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"
    }
   }

I have no idea what Array.reverse is. Array.prototype.reverse has existed forever (sine IE 5.5), but I doubt this is a problem with Jest

With webpack or storybook this error didn't happen only with jest, I'll test passing the babel config directly on create transform

Was this page helpful?
0 / 5 - 0 ratings

Related issues

StephanBijzitter picture StephanBijzitter  路  3Comments

gustavjf picture gustavjf  路  3Comments

Secretmapper picture Secretmapper  路  3Comments

nsand picture nsand  路  3Comments

jardakotesovec picture jardakotesovec  路  3Comments