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.

[v5] jest fails to run

See original GitHub issue

I’ve just bumped my code to v5 as I’m currently experiencing the #65 bug often. My tests dont run however (detail below). I’m guessing this is because the current build target and module ts settings are super modern.

Could they be downgraded to "target":"es5" and "module": "commonjs" ?

ps congrats on the first v5 alpha!

  ● 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/project/node_modules/redlock/dist/index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { randomBytes, createHash } from "crypto";
                                                                                             ^^^^^^

    SyntaxError: Cannot use import statement outside a module

    > 1 | import Redlock, { Lock } from "redlock";

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
SimenBcommented, Aug 25, 2021

Jest executes all code in a vm, and vm’s support for ESM is sorta sketchy still (see first link in the error in the OP: https://jestjs.io/docs/ecmascript-modules)

Best solution for Jest here is to ship a CJS implementation (in addition to the ESM one) referenced in main and using exports for the ESM one: https://nodejs.org/api/packages.html#packages_package_entry_points

(note that Jest does not support this field yet, which is why main is still needed)

0reactions
mike-marcaccicommented, Nov 26, 2021

I just published v5.0.0-beta.1 which should fix this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to run jest test case - Stack Overflow
try installing. npm i --save-dev enzyme enzyme-adapter-react-16. Add transform-class-properties to .babelrc file like below -
Read more >
vscode-jest - Visual Studio Marketplace
Jest failed to run ; Performance issue? Intermittent errors for (npm/yarn/node) command not found during test run or debugging ...
Read more >
Getting all files containing a failed test from a jest run
The following approach is _one way_ to get a list of file names with failed tests after all. You can run jest such...
Read more >
test suite failed to run cannot find module jest - You.com
4", "vue-jest": "^5.0.0-alpha.7",. This hint came from a discussion relating to this gist.
Read more >
@testing-library/jest-dom - npm
Use this matcher to avoid double negation in your tests. This custom matcher does not take into account the presence or absence of...
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