@nrwl/node library babel jest setting does not work
See original GitHub issueCurrent Behavior
After scaffolding a brand new node library using @nrwl/node and selecting the babelJest option tests do not run for the generated library.
Expected Behavior
Tests should be able to run in a new project
Steps to Reproduce
- Generate a new NX workspace
- Add the
@nrwl/nodepackage - Generate a node library choosing the
babelJestoption, eg:
npm run nx generate @nrwl/node:library – --name=babel-test
–buildable
–importPath=@some-org/babel-test
–publishable
–standaloneConfig
–strict
–no-interactive
–babelJest
- Run tests for the newly create library
npm run test babel-test:test - Observe that the tests fail to run
Failure Logs
FAIL babel-test packages/babel-test/src/lib/babel-test.spec.ts
● Test suite failed to run
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
By default "node_modules" folder is ignored by transformers.
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation
Details:
/home/jesse/code/deepkit-community/modules/packages/babel-test/src/lib/babel-test.spec.ts:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import { babelTest } from './babel-test';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Runtime.createScriptFromCode (../../node_modules/jest-runtime/build/index.js:1479:14)
at TestScheduler.scheduleTests (../../node_modules/@jest/core/build/TestScheduler.js:333:13)
Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: 0.218 s
Environment
Node : 14.15.4
OS : linux x64
npm : 6.14.14
nx : Not Found
@nrwl/angular : Not Found
@nrwl/cli : 12.7.2
@nrwl/cypress : Not Found
@nrwl/devkit : 12.7.2
@nrwl/eslint-plugin-nx : 12.7.2
@nrwl/express : Not Found
@nrwl/jest : 12.7.2
@nrwl/linter : 12.7.2
@nrwl/nest : Not Found
@nrwl/next : Not Found
@nrwl/node : 12.7.2
@nrwl/nx-cloud : 12.3.10
@nrwl/react : Not Found
@nrwl/schematics : Not Found
@nrwl/tao : 12.7.2
@nrwl/web : Not Found
@nrwl/workspace : 12.7.2
@nrwl/storybook : Not Found
@nrwl/gatsby : Not Found
typescript : 4.3.5
Issue Analytics
- State:
- Created 2 years ago
- Reactions:7
- Comments:14 (6 by maintainers)
Top Results From Across the Web
jest encountered an unexpected token uuid - You.com | The AI ...
Jest encountered an unexpected token This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not...
Read more >@nrwl/workspace:library | Nx
Useful for Node libraries that are not compiled by Babel. setParserOptionsProject. boolean. Default: false.
Read more >nrwl-nx/community - Gitter
I'd like to do something like nx run project:target param1 param2 where ... By default, if Jest sees a Babel config, it will...
Read more >Supported technologies: Nx/Nrwl - Wallaby.js
If jest does not run from the command-line for an application/library, you should be able to modify its jest.config.js to run by adding...
Read more >Nx Angular: Jest encountered an unexpected token
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration....
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 Free
Top 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

Any updates? I am also facing the same error.
@markogresak thanks!
The error disappears. I am now getting the
SyntaxError: Cannot use import statement outside a moduleError.I’ll try to do some config tweaking.