Jest: File in node_modules not transformed (related to transformIgnorePatterns)

Created on 4 Jan 2019  路  6Comments  路  Source: facebook/jest

馃悰 Bug Report

In my jest config, I have the following:

transformIgnorePatterns: ['node_modules/(?!(react-apollo/test-links(.js)?))'],

And in my test file, I have this:

import { MockLink } from 'react-apollo/test-links';

And I get this error:

    Jest encountered an unexpected token

    webapp/node_modules/react-apollo/test-links.js:25
    import { ApolloLink, Observable } from 'apollo-link';
    ^^^^^^

    SyntaxError: Unexpected token import

    > 4 | import { MockLink } from 'react-apollo/test-links';
        | ^

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:404:17)
      at Object.<anonymous> (assets/comps/TcombFactories/__tests__/loaders-test.js:4:1)

Expected behavior

I have traced the file into script_transformer.js. The code is not transpiled, despite the fact that willTransform equals true. So transformSource is returning untransformed content:

const processed = transform.process(content, filename, this._config, {
   instrument: instrument
});

Both transformedSource.code and content are the same. I expect the result to be in ES5, but it's not.

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: macOS High Sierra 10.13.6
    CPU: (4) x64 Intel(R) Core(TM) i5-4250U CPU @ 1.30GHz
  Binaries:
    Node: 8.11.2 - ~/.nvm/versions/node/v8.11.2/bin/node
    Yarn: 1.12.3 - /usr/local/bin/yarn
    npm: 5.6.0 - ~/.nvm/versions/node/v8.11.2/bin/npm
  npmPackages:
    jest: ^23.0.0 => 23.6.0
Bug

Most helpful comment

Could you please include your babel config? If you're transpiling node_modules and you're using babel v7 you have to use babel.config.js(read more here: https://jestjs.io/docs/en/getting-started#using-babel)

All 6 comments

Could you please include your babel config? If you're transpiling node_modules and you're using babel v7 you have to use babel.config.js(read more here: https://jestjs.io/docs/en/getting-started#using-babel)

Thanks, that fixes it.

@volkanunsal how did you solve it?
Could you please share your configuration?

@domkrel I wasn't using a babel.config.js file.

@volkanunsal thanks for the hint. I dropped my babel.rc in favor for babel.config.js now.

I wonder if this still persists? I have just encountered the same problem and although i am using transformIgnorePatterns in package.json inside jest object. I have also used babel.config.js as mentioned however still the same issue. Just like @volkanunsal i have also debugged the script_transformer.js and found that the values are same however still the same issue :( any hint help?

Was this page helpful?
0 / 5 - 0 ratings