Jest unable to resolve node_modules at the root in Yarn workspace
See original GitHub issueJest 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:
- Created 6 years ago
- Reactions:24
- Comments:21
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m not convinced that symlinking everything is the right solution to what is definitely a real issue. It might be worth reopening this.
@SimenB I did a reproduction repo. You can find it here jest-resolve-issue