[Bug]: jest cannot parse the ECMAScript module - oclif
See original GitHub issueVersion
26.0.0, 27.0.0, 28.0.0
Steps to reproduce
- Clone Repo: https://github.com/twilio-labs/plugin-rtc.git , Branch:cli-core-upgrade
- Run
npm test
- Testing suite test/e2e/e2e.test.js will fail.
Expected behavior
I expect the test suite to run at least.
Actual behavior
The testing suite fails with an error: [more details in below box] FAIL test/e2e/e2e.test.js ● Test suite failed to run
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 plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/en/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/en/configuration.html
Details:
/home/circleci/plugin-rtc/node_modules/@oclif/core/lib/command.js:51
delete this.globalFlags?.json;
^
SyntaxError: Unexpected token '.'
Additional context
> @twilio-labs/plugin-rtc@0.8.5 test /home/circleci/plugin-rtc
> TZ=utc jest -i --coverage "--verbose"
FAIL test/e2e/e2e.test.js
● Test suite failed to run
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 plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/en/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/en/configuration.html
Details:
/home/circleci/plugin-rtc/node_modules/@oclif/core/lib/command.js:51
delete this.globalFlags?.json;
^
SyntaxError: Unexpected token '.'
1 | const { findApp, findConversationsService } = require('../../../../helpers');
> 2 | const { TwilioClientCommand } = require('@twilio/cli-core').baseCommands;
| ^
3 |
4 | class DeleteCommand extends TwilioClientCommand {
5 | async run() {
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
at Object.<anonymous> (node_modules/@oclif/core/lib/index.js:6:19)
at Object.<anonymous> (node_modules/@twilio/cli-core/src/base-commands/base-command.js:1:129)
at Object.<anonymous> (node_modules/@twilio/cli-core/src/index.js:3:18)
at Object.<anonymous> (src/commands/rtc/apps/video/delete.js:2:33)
at Object.<anonymous> (test/e2e/e2e.test.js:2:23)
Environment
System:
OS: macOS 12.2.1
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Binaries:
Node: 16.14.0 - /usr/local/bin/node
Yarn: 1.22.19 - ~/CLI/CLI_GA/plugin-rtc/node_modules/.bin/yarn
npm: 8.3.1 - /usr/local/bin/npm
npmPackages:
jest: ^26.0.0 => 28.1.3
Issue Analytics
- State:
- Created a year ago
- Comments:6
Top Results From Across the Web
After updating npm packages. Error: Could not parse ...
Please use eslint-webpack-plugin warning nuxt-build-optimisations@1.0.7: module has been renamed to nuxt-webpack-optimisations, see https:// ...
Read more >Jest not parsing es6: SyntaxError: Unexpected token import
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 >Error Handling · oclif: The Open CLI Framework
oclif handles intentionally - and unintentionally - thrown errors in two places. First in the Command.catch method and then, finally, in the bin/run...
Read more >require() of es module is not supported
A secondary problem is that the ESM builds of the Gutenberg packages are not declared via exports in package.json, and some environments (like...
Read more >Running Jest when you are importing a file which ...
When you are running jest and encounter the error below, the solution is simple. You need to add transformIgnorePatterns in the jest config....
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 assume it’s an issue of using node 13. If not, please create a new issue with a minimal reproduction
FWIW, optional chaining has nothing to do with ES modules.
That said, I’m unable to reproduce (getting a different error).
(This is why the template asks for minimal reproductions 😅)