question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug]: jest cannot parse the ECMAScript module - oclif

See original GitHub issue

Version

26.0.0, 27.0.0, 28.0.0

Steps to reproduce

  1. Clone Repo: https://github.com/twilio-labs/plugin-rtc.git , Branch:cli-core-upgrade
  2. Run npm test
  3. 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:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
SimenBcommented, Oct 13, 2022

I assume it’s an issue of using node 13. If not, please create a new issue with a minimal reproduction

1reaction
SimenBcommented, Oct 13, 2022

FWIW, optional chaining has nothing to do with ES modules.


That said, I’m unable to reproduce (getting a different error).

 FAIL  test/e2e/e2e.test.js
  ● Test suite failed to run

    username is required

      10 | const superagent = require('superagent');
      11 |
    > 12 | const twilioClient = require('twilio')(process.env.TWILIO_API_KEY, process.env.TWILIO_API_SECRET, {
         |                                       ^
      13 |   accountSid: process.env.TWILIO_ACCOUNT_SID,
      14 | });
      15 |

      at new Twilio (node_modules/twilio/lib/rest/Twilio.js:140:11)
      at initializer (node_modules/twilio/lib/index.js:10:10)
      at Object.<anonymous> (test/e2e/e2e.test.js:12:39)

(This is why the template asks for minimal reproductions 😅)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found