nx: where need to specify transformIgnorePatterns to fix "Jest encountered an unexpected token
Please make sure you have read the submission guidelines before posting an issue
Prerequisites
Please answer the following questions for yourself before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.
- I am running the latest version
- I checked the documentation and found no answer
- I checked to make sure that this issue has not already been filed
- I’m reporting the issue to the correct repository (not related to Angular, AngularCLI or any dependency)
Expected Behavior
Please describe the behavior you are expecting
Current Behavior
What is the current behavior?
Failure Information (for bugs)
Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template.
Steps to Reproduce
Please provide detailed steps for reproducing the issue.
- step 1
- step 2
- …
Context
Please provide any relevant information about your setup:
- version of Nx used
- version of Angular CLI used
angular.jsonconfiguration- version of Angular DevKit used
- 3rd-party libraries and their versions
- and most importantly - a use-case that fails
A minimal reproduce scenario using allows us to quickly confirm a bug (or point out coding problem) as well as confirm that we are fixing the right problem.
Failure Logs
Please include any relevant log snippets or files here.
Other
Any other relevant information that will help us help you.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 24 (4 by maintainers)
I’m a bit confused. I would have expected that when creating a new angular app with nx the setup will work out of the box. And jest not really supporting modules seams somehow awkward for a so much hyped library. It’s really disappointing to see how much trouble it is using modules.
Adding this to root
jest.config.jsworked for me:See https://stackoverflow.com/questions/42260218/jest-setup-syntaxerror-unexpected-token-export/54117206#answer-54117206
I’m having the same issue with the latest nx version
Hi there,
I’m hoping someone can assist, as I’m sitting with a similar issue.
In my case, this is the package that is in question
What I’ve tried;
testPathIgnorePatterns: [ '/node_modules/?!(@appnest)' ]testPathIgnorePatterns: [ '../../node_modules/?!(@appnest)' ]allowJs: trueto both global and local tsconfig.spec.json filesbabel-config.jswith contentWhat I have no idea about is this part for my instance (in the jest.config.js, as mentioned in the comment above)
"moduleNameMapper": { "^lodash-es$": "lodash" }My environment is a newly created workspace; npm init nx-workspace@latest myworkspace npm i @appnest/web-router
Updating app.component.ts to look as follows
I have no idea what to try differently
This is not nx related. Jest dropped the support for babel 6 that means that it does not read the babel.rc file anymore. Create a babel.config.js file with your configs should solve the problem https://jestjs.io/docs/en/getting-started#using-babel
In my case using react apps, after migrating to 14.6 I had to update my apps jest.config.ts to choose @nrwl/react/babel preset.
You can set this in the
jest.config.jsat root level.