Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest #40

Open
calderon opened this issue Apr 29, 2024 · 2 comments
Open

Jest #40

calderon opened this issue Apr 29, 2024 · 2 comments

Comments

@calderon
Copy link

calderon commented Apr 29, 2024

Hi! I have included @anycable/web (lastest version) and running Jest I am getting:

    Details:

    /Users/dani/code/project/node_modules/@anycable/web/index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import {
                                                                                      ^^^^^^

    SyntaxError: Cannot use import statement outside a module

       7 |   useState,
       8 | } from 'react';
    >  9 | import {
         | ^
      10 |   Cable,
      11 |   createCable,
      12 | } from '@anycable/web';

Is there anything to add in jest config or such? What am I missing?

@palkan
Copy link
Member

palkan commented Apr 29, 2024

I suggest trying --experimental-vm-modules to the jest command (like we do here). See also: https://jestjs.io/docs/ecmascript-modules

@calderon
Copy link
Author

calderon commented Apr 30, 2024

@palkan I tried it:

NODE_OPTIONS=--experimental-vm-modules jest --coverage

The error is different but it is still in there:

    Must use import to load ES Module: /Users/dani/code/project/node_modules/@anycable/web/index.js

       7 |   useState
       8 | } from 'react';
    >  9 | import {
         | ^
      10 |   Cable,
      11 |   createCable,
      12 | } from '@anycable/web';

Using it in a project:

  • React 18.2 with TS
  • Node 20.4.0
  • Jest 29.7.0 with ts-jest

For now I am disabling it in my test environment as a desperate measure

jest.mock('@anycable/web', () => ({}));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants