jest: Jest unable to resolve node_modules at the root in Yarn workspace
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.
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 24
- Comments: 21 (4 by maintainers)
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
I solved this by using
moduleNameMapper
, where@fta/components-token
is the name of a package of my workspace and<rootDir>../token/src
is the path to its index:or
'@fta/components-(.*)$': '<rootDir>../$1/src',
in case the package sufix name is the same of the folder.Having this issue as well
I have the same issue and I can’t find a workaround
Can anyone out together a reproduction? The repo from @kcjonson should be fixed in RN 0.59 due to https://github.com/facebook/react-native/pull/22972
You shouldn’t need to do
..
etc in your config, so I’d love to get this fixed