software-mansion / react-native-reanimated

React Native's Animated library reimplemented
https://docs.swmansion.com/react-native-reanimated/
MIT License
9.03k stars 1.3k forks source link

SyntaxError: Cannot use import statement outside a module #4071

Closed Jeet989 closed 1 year ago

Jeet989 commented 1 year ago

Description

Unable to run jest after installing the navigation dependency and the required other dependencies. I think so you can reproduce this issue by creating a new project as well. Here, I have also created a new project with the same issue and below is the git link.

Here is the issue screenshot:

image

Steps to reproduce

Just create a new project and add the react navigation dependencies. Then add the reanimated library and configure it with the proper jest files and then you will be able to get the same issue.

Snack or a link to a repository

https://github.com/Jeet989/Testing

Reanimated version

^2.14.4

React Native version

0.71.3

Platforms

Android, iOS

JavaScript runtime

None

Workflow

React Native (without Expo)

Architecture

None

Build type

None

Device

None

Device model

No response

Acknowledgements

Yes

andrzej-hanusek-tg commented 1 year ago

@Jeet989 How did you resolve this issue?

Jeet989 commented 1 year ago

@andrzej-hanusek-tg not yet. I am trying to see if I get any solution

andrzej-hanusek-tg commented 1 year ago

@Jeet989

Try to with jest.config.js like below

{
  "preset": "react-native",
  "moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
  "setupFiles": ["./node_modules/react-native-gesture-handler/jestSetup.js"],
  "setupFilesAfterEnv": ["./jest-setup.js"],
  "transformIgnorePatterns": ["jest-runner"],
  "testTimeout": 30000,
  "moduleNameMapper": {
    "\\.svg": "<rootDir>/__mocks__/svgMock.js",
    "^@/(.*)$": "<rootDir>/src/$1"
  }
}

and jest-setup.js

import '@testing-library/jest-native/extend-expect';
require('react-native-reanimated/lib/reanimated2/jestUtils').setUpTests();

global.ReanimatedDataMock = {
  now: () => Date.now(),
};

jest.mock('react-native/Libraries/EventEmitter/NativeEventEmitter');
});
Tohix commented 1 year ago

Have the same problem

markcabadsan commented 8 months ago

Try to add react-native-reanimated to transformIgnorePatterns in package.json

 "transformIgnorePatterns": [
      "node_modules/(?!(@react-native|react-native|react-native-reanimated)/)"
    ],