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

Running yarn test fails when integrating Sentry - SyntaxError: Unexpected token export at import * #668

Closed
3 of 7 tasks
hkellaway opened this issue Sep 24, 2019 · 7 comments

Comments

@hkellaway
Copy link

OS:

  • Windows
  • MacOS
  • Linux

Platform:

  • iOS
  • Android

SDK:

  • @sentry/react-native
  • react-native-sentry

react-native version: 0.60.6

Init Code:

Sentry.init({
  dsn: 'https://...@sentry.io/...'
});

I have following issue:

After setting up Sentry per the docs, running yarn test fails.

More specifically, it fails after running Sentry Wizard. The following error occurs:

/MyApp/node_modules/@sentry/react-native/dist/js/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export { Severity, Status } from "@sentry/types";
                                                                                         ^^^^^^

SyntaxError: Unexpected token export

  25 | } from 'react-native/Libraries/NewAppScreen';
  26 | 
> 27 | import * as Sentry from '@sentry/react-native';
     | ^
  28 | 
  29 | Sentry.init({ 
  30 |   dsn: 'MY_DSN', 

  at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
  at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
  at Object.<anonymous> (App.js:27:1)

Steps to reproduce:
Here is a sample project demonstrating the issue along with STRs:

https://github.com/hkellaway/sentry-reactnative-yarntest-error-demo

Generally, the least you have to do to produce this error is to:

  • generate a brand new project with react-native CLI
  • follow the Sentry docs for "Integrating the SDK"
  • after the Sentry Wizard step, run yarn test

Actual result:
yarn test fails after setting up Sentry for a React Native project

Expected result:
Integrating Sentry should not disrupt yarn test for React Native projects

@HazAT
Copy link
Member

HazAT commented Sep 25, 2019

Google spit out this:

https://jestjs.io/docs/en/tutorial-react-native#transformignorepatterns-customization

It fixes it for me if I add this to package.json:

 "jest": {
    "preset": "react-native",
    "transformIgnorePatterns": [
      "node_modules/(?!(react-native|react-native-cookies|@sentry/react-native)/)"
    ]
  }

@HazAT HazAT closed this as completed Sep 25, 2019
@hkellaway
Copy link
Author

hkellaway commented Sep 25, 2019

i appreciate you investigating & responding despite it not being a Sentry issue, rather a Jest configuration

for others who may encounter this - confirmed this does fix error message

@naguigui
Copy link

naguigui commented Oct 8, 2019

Thank god I found this post.

@borgogelli
Copy link

The right config for Expo Sdk is

"jest": {
  "preset": "jest-expo",
  "transformIgnorePatterns": [
    "node_modules/(?!(jest-)?react-native|react-clone-referenced-element|@react-native-community|expo(nent)?|@expo(nent)?/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|@sentry/.*)"
  ]
}

see it at https://docs.expo.io/guides/testing-with-jest/

@makarkotlov
Copy link

I fixed it by mocking Sentry in jest.setup.js:
jest.mock('@sentry/react-native', () => ({ init: () => jest.fn() }));

and adding jest.setup.js to jest.config.js:

module.exports = {
  preset: 'react-native',
  transform: {
    '\\.js$': '<rootDir>/node_modules/react-native/jest/preprocessor.js',
  },
  cacheDirectory: '.jest/cache',
  setupFiles: ['./jest.setup.js'],
};

@Rehan-05
Copy link

Not working, any solution from above these😒

@marandaneto
Copy link
Contributor

Please raise a new issue with more context in case something is not working.

@getsentry getsentry locked and limited conversation to collaborators Aug 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants