Skip to content

Delete or allow changing Jest transformIgnorePatterns option so tests won't fail when importing ES2015 modules from node_modules #2943

Closed
@gykf

Description

@gykf

Is this a bug report?

No, it's not.

This is a proposal to delete the Jest configuration option transformIgnorePatterns in package.json of new CRA apps, or at least enable changing the option without ejecting.

Users of CRA may want to import 3rd-party modules written in ES2015 from the node_modules directory. This works as expected when using the Webpack build. However, it fails when running Jest tests on the module which imports an ES2015 module from node_modules. The test runner throws a SyntaxError (see #2940) because Jest doesn't transform the dependencies in node_modules.

I don't think it should be a requirement to pre-compile modules in node_modules to an old version of JS before running Jest tests with them. Users may not have control over the modules in node_modules, being unable to pre-compile them before running the tests (without forking them). Importing ES2015 modules from node_modules works as expected when using Webpack, there's no requirement to pre-compile them in a separate step before running the Webpack build. Files and modules that get compiled without issue with Webpack fail to run with Jest. This behaviour between Webpack and Jest is inconsistent, thus unexpected and confusing for me and probably other users as well.

So I suggest removing the transformIgnorePatterns strings from package.json. If there are any concerns regarding the transformation of modules in node_modules (e.g. speed) with Jest, I would at least want to have a way of changing the option without ejecting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions