Skip to content

Undocumented breaking change with moduleDirectories config in Jest v20 #3535

Description

@lourd

Hey y'all, congrats on the release of v20! A lot of really great additions, as well as critical, less-flashy work refactoring for the future. Thank you for your efforts 🙏🏼

Just updated a couple projects and ran into an undocumented breaking change. It's not really an issue to fix, but I want to document it for other folks who run into it.

After upgrading from v19 to v20 I had all of my tests failing with various Cannot find module errors. First it was coming from a script loading polyfills so I was seeing Cannot find module 'babel-polyfill' from 'polyfills.js', so I thought it was part of the changes to Jest no longer loading babel-polyfill internally. I commented that file out though and got Cannot find module 'once' from 'queueRunner.js', which was definitely not in my codebase. At that point I started playing around with some config changes to see what might affect it.

Turned out to be the moduleDirectories configuration. I've been using "<rootDir>" in each entry, which doesn't seem to be valid any longer. Once I dropped that prefix that fixed everything.

     "moduleDirectories": [
-      "<rootDir>/app/",
-      "<rootDir>/node_modules/"
+      "app",
+      "node_modules"
     ],

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions