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]: Cannot use with lit-element due to ESM errors, even with transformIgnorePatterns

See original GitHub issue

Version

27.0.6

Steps to reproduce

  1. Clone my minimal reproducible repo: https://github.com/cdrini/lit-jest-babel-test
  2. Run npm install
  3. Run npx jest

Expected behavior

I expect to see the tests run

Actual behavior

The test is not run with this error:

    Details:

    C:\...\lit-jest-babel-test\node_modules\lit-element\lit-element.js:57
    import { render } from 'lit-html/lib/shady-render.js';
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module

Despite the fact that this is file should be babel-ed by my jest.config.js

Additional context

No response

Environment

System:
    OS: Windows 10 10.0.19042
    CPU: (8) x64 Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
  Binaries:
    Node: 14.16.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.17.3 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 6.14.7 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    jest: ^27.0.6 => 27.0.6

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
cdrinicommented, Aug 25, 2021

Gaaaah, I finally figured it out! Huge thanks to @austinkelleher and https://github.com/facebook/jest/issues/6229#issuecomment-403539460 .

The issue was my .babelrc needed to be renamed to babel.config.js 😖 . Is there any way we could maybe surface this as a warning on https://jestjs.io/docs/ecmascript-modules ? Cause otherwise the fix was really simple and logical; just add lit-element/lit-html to the list of ignored transforms.

0reactions
github-actions[bot]commented, May 26, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest throwing error, "transformIgnorePatterns is not working"
When I run my test I am getting the following error. ○ Test suite failed to run Jest encountered an unexpected token This...
Read more >
ts-jest syntaxerror: unexpected token 'export'
I know the problem is that the library imports es6 modules and jest does not understand them. Any idea how to make them...
Read more >
Jest Unexpected Token a.k.a. won't transpile error - home/pierce
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 >
MIGRATION.md - Storybook
For example, if you're in a webpack5 project but still use Storybook's default webpack4 builder, ... Error: Cannot find module 'react-dom/package.json'.
Read more >
How I Fixed The Unexpected Token Error In Jest
I recently ran into a nasty problem that took the better part of a day to get straight. So I'm gonna... Tagged with...
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