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

Cannot use import statement outside a module #1475

Open
1 of 6 tasks
aymkin opened this issue Dec 11, 2023 · 7 comments
Open
1 of 6 tasks

Cannot use import statement outside a module #1475

aymkin opened this issue Dec 11, 2023 · 7 comments
Labels
bug Something isn't working v1 gluestack-ui v1

Comments

@aymkin
Copy link

aymkin commented Dec 11, 2023

Description

Default project can not run tests due to wrong jest config

CodeSandbox/Snack link

No response

Steps to reproduce

  1. Run from terminal npm create gluestack
  2. Select Mobile app (React Native + gluestack-ui), the rest can be dafault
  3. cd my-app && npm run test
  4. See error
❯ npm run test

> reactNativeApp@1.0.0 test
> jest

 FAIL  __tests__/App.test.tsx
  ● Test suite failed to run

    Jest encountered an unexpected token

    Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

    Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

    By default "node_modules" folder is ignored by transformers.

    Here's what you can do:
     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
     • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
     • 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/configuration
    For information about custom transformations, see:
    https://jestjs.io/docs/code-transformation

    Details:

    /Users/aymkin/Projects/my-app/node_modules/@gluestack-ui/config/build/gluestack-ui.config.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import { AnimationResolver } from '@gluestack-style/animation-resolver';
                                                                                      ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      14 | } from 'react-native';
      15 | import {Colors} from 'react-native/Libraries/NewAppScreen';
    > 16 | import {config} from '@gluestack-ui/config';
         | ^
      17 | import {GluestackUIProvider, Box, Text, Image} from '@gluestack-ui/themed';
      18 |
      19 | const FeatureCard = ({iconSvg, name, desc}: any) => {

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1505:14)
      at Object.require (App.tsx:16:1)
      at Object.require (__tests__/App.test.tsx:7:1)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.238 s
Ran all test suites.

"@gluestack-style/react": "latest", 1.0.26
"@gluestack-ui/themed": "latest", 1.0.25
"@gluestack-ui/config": "latest", 1.0.8
"@legendapp/motion": "latest", 2.2.1

Expectation

I would expect that default cofig is configured to use latest Jest

gluestack-ui Version

latest

Platform

  • Expo
  • React Native CLI
  • Next
  • Web
  • Android
  • iOS

Other Platform

No response

Additional Information

No response

@aymkin aymkin added the bug Something isn't working label Dec 11, 2023
@Gluant101 Gluant101 moved this from Backlog to Todo in gluestack support Dec 12, 2023
@Gluant101 Gluant101 moved this from Todo to Backlog in gluestack support Dec 13, 2023
@Gluant101
Copy link
Contributor

Thanks for reporting the issue. We'll give an update soon.

@kk3939
Copy link

kk3939 commented Dec 28, 2023

Thanks for reporting the issue. We'll give an update soon.

I used Expo and encountered this bug.
I tried this way, but I can't fix.

#1095

I'm looking forward to the updated version and advice to test with jest.

@2n2n
Copy link

2n2n commented Jan 29, 2024

I'm having the same issue, any luck? If there's a way to mock the config files this issue will go away.

@esteban-serfe
Copy link

I'm having the same issue... Any news on this front?

@cedricfressin
Copy link

cedricfressin commented Apr 8, 2024

Did you tried adding this to your Jest config:

    "transformIgnorePatterns": [
      "node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|@gluestack-ui/*|@gluestack-style/*|@legendapp/*|react-native-svg)"
    ]

@ngcvm
Copy link

ngcvm commented Jan 20, 2025

Hi, Is there any walkaround to fix this problem? I have tried using the Jest transformIgnorePatterns, but it didn't work.

@sbunking
Copy link

Can we please get some help with this? I'm encountering the same problem and transformIgnorePatterns fix doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v1 gluestack-ui v1
Projects
Status: Backlog
Status: Backlog
Development

No branches or pull requests