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 unable to resolve node_modules at the root in Yarn workspace

See original GitHub issue

Jest v22.1.1

To enhance lerna in my project I have enabled yarn workspaces. Since then transformIgnorePatterns does not seem to be able to resolve node_modules at the root.

The same jest config used before switching to yarn workspace:

"jest": {
    "modulePaths": [
        "<rootDir>/src",
        "<rootDir>/node_modules"
      ],
    "setupTestFrameworkScriptFile": "./jest-setup.js",
    "transformIgnorePatterns": [
      "node_modules/(?!lodash-es|react-virtualized|redux-form)"
    ],
    "testPathIgnorePatterns": [
      "/node_modules",
      "/lib/",
      "/es/"
    ],
    "testRegex": "src/.*\\.spec\\.js$",
    "testEnvironment": "jsdom"
  }

This causes Unexpected token import error.

/path/to/project/node_modules/redux-form/es/Field.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import createField from './createField';
                                                                                             ^^^^^^

    SyntaxError: Unexpected token import

      1 | import React from 'react';
      2 | import PropTypes from 'prop-types';
    > 3 | import ReduxFormField from 'redux-form/es/Field';
      4 | import isEmpty from 'lodash/isEmpty';
      5 | import reduce from 'lodash/reduce';
      6 | import keys from 'lodash/keys';

Is there workaround or proper configuration for allowing jest to play nice in yarn workspaces?

Thanks.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:24
  • Comments:21

github_iconTop GitHub Comments

5reactions
egidcommented, Feb 2, 2018

I’m not convinced that symlinking everything is the right solution to what is definitely a real issue. It might be worth reopening this.

4reactions
tamazlykarcommented, Jul 4, 2020

Can anyone out together a reproduction?

@SimenB I did a reproduction repo. You can find it here jest-resolve-issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can not find jest in subpackage of yarn workspace
I have jest installed "locally" in the package with all the tests. But if I check node_modules/ after a yarn install , I...
Read more >
Support yarn workspaces (better indexing of node_modules ...
What steps will reproduce the problem? 1. Create a multi-package workspace project with yarn workspaces 2. Try and import code between different projects, ......
Read more >
Working with monorepos - Expo Documentation
Yarn workspaces require the root package.json to be private. ... nodeModulesPaths = [ path.resolve(projectRoot, 'node_modules'), path.resolve(workspaceRoot, ...
Read more >
Configuring Jest
For example, with the following configuration jest will fail if there is less than ... the resolution of this file will be relative...
Read more >
React Native monorepo for every platform: Android & iOS
Once you've updated the nohoist list, run yarn reset && yarn from the project root to re-install the dependencies using the updated settings....
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