Hi team. Im running into a React Native SDK error ...
# support
a
Hi team. Im running into a React Native SDK error when I try to
yarn test
with Jest
Copy code
node_modules/@rudderstack/rudder-sdk-react-native/index.js:1
    
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import { NativeModules, Platform } from 'react-native';
                                                                                      ^^^^^^

SyntaxError: Cannot use import statement outside a module

import rudderClient from '@rudderstack/rudder-sdk-react-native'
Has this been raised as an issue previously? I’ve tried a few solutions, but nothing seems to solve this for me currently. Thanks
m
Hey There! 👋 Your message has been received by the RudderStack team. We will forward this request to your Technical Account Manager, and they will get back to you shortly. Please use the thread for any additional comments.
Let me see if the team can help on this?
k
CC @calm-yak-10773
a
Thanks, look forward to hearing from you
c
Hey @alert-shampoo-49789, Could you please ensure you React Native project contains Android and iOS folders?
a
Sure does!
gratitude thank you 1
c
Thanks for confirming that. Actually, that is a most common scenario when we observe this error. Next, can you please try this: https://stackoverflow.com/a/67227427 solution once and if the issue persist, I’ll request you to share the minimal reproducible example or steps to reproduce this, so that I can investigate further on my side.
a
Hey @calm-yak-10773 - Added to our
babel.config.js
, but I’m still seeing those same errors.
Would it have anything to do with needing to mock Rudderstack for Jest?
c
Would it have anything to do with needing to mock Rudderstack for Jest?
I don’t think so. Did you tried this steps as well:
Copy code
npm install --save-dev @babel/core @babel/preset-env
Also consider adding this:
Copy code
presets: ['@babel/preset-env', '@babel/preset-react'],
As per my understanding this is a babel/jest configuration issue. I’m trying to reproduce this issue at my end but currently unable to. Hence, it would be helpful, if you consider sharing a minimal reproducible example.
a
Hi, yes I updated those two things too. Sorry I’m not sure what you’re after with “a minimal reproducible example.” Code Snippets?
c
I’m basically asking you to create a new React Native project with the minimal configuration possible to reproduce this error and share it to me, so that I can look into it.
Hey @alert-shampoo-49789, I’m able to reproduce the issue at my end just now and I tried you earlier suggestion:
Would it have anything to do with needing to mock Rudderstack for Jest?
It worked and solved the issue. Please add this line in your test file to solve this issue:
Copy code
jest.mock("@rudderstack/rudder-sdk-react-native", () => jest.fn());
Please LMK if it works or not.
a
Hey Abhishek, I was just about to message you back to say we solved it with mocks 👍
❤️ 1
Thanks for your help
❤️ 1