New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jest encountered an unexpected token when importing publishable library. #12360
Comments
This change was sufficient to get the tests passing, should this be the default behaviour? //libs/react-b/jest.config.ts
/* eslint-disable */
export default {
displayName: 'react-b',
preset: '../../jest.preset.js',
transform: {
- '^.+\\.[tj]sx?$': 'babel-jest',
+ '^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nrwl/react/babel'] }],
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/libs/react-b',
};
|
This is the default behavior as of v14.6.0 and a migration was provided at that point to update it. Can you confirm this migration ran for you workspace? https://github.com/nrwl/nx/blob/master/packages/react/src/utils/jest-utils.ts https://github.com/nrwl/nx/blob/master/packages/react/migrations.json#63 |
This was a brand new repository created with |
I am on Nx 15.0.3. When generating a new lib with the React generator: I still get the wrong transform expression, I guess:
The only place where the transform is the one suggested above, is the apps. All the libraries I generated have the old one. |
Solved by renaming the Babel configuration file
{
"presets": [
[
"@nrwl/react/babel",
{
"runtime": "automatic",
"useBuiltIns": "usage"
}
]
],
"plugins": []
}
/* eslint-disable */
export default {
displayName: 'react-b',
preset: '../../jest.preset.js',
transform: {
'^.+\\.[tj]sx?$': 'babel-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/libs/react-b',
};
|
Why is this issue closed? Shouldn't new libraries created using the generators already have the correct name for the babel config file? And why is it working renaming it? :/ |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
Current Behavior
I want to independently publish
@example/a
and@example/b
.@example/b
will have a dependency on@example/a
.When running jest on
@example/b
it fails to run due to ESM syntax.nx/packages/jest/preset/jest-preset.ts
Lines 12 to 14 in 77b57b7
I updated the rollup config to produce a cjs build, however this did not help.
Expected Behavior
Tests should pass.
Steps to Reproduce
git clone git@github.com:jamime/nx-jest-issue.git
npm i
npx nx test react-b
or
npx create-nx-workspace example --preset react --appName demo
npx nx g @nrwl/react:library react-a --publishable --importPath @example/a
npx nx g @nrwl/react:library react-b --publishable --importPath @example/b
// libs/react-b/scr/lib/react-b.tsx import styles from './react-b.module.css'; + import { ReactA } from '@example/a'; /* eslint-disable-next-line */ export interface ReactBProps {} export function ReactB(props: ReactBProps) { return ( <div className={styles['container']}> <h1>Welcome to ReactB!</h1> <ReactA /> </div> ); } export default ReactB;
npx nx test react-b
Failure Logs
Environment
The text was updated successfully, but these errors were encountered: