react-native-splash-screen
react-native-splash-screen copied to clipboard
[yarn test issue] SyntaxError: Cannot use import statement outside a module
react native info
Version Info: "3.2.0"
What platform does your issue occur on? (Android/iOS/Both)
=> Android
Problem
: when i run yarn test
, it ran well without importing "react-native-splash screen" to App.tsx but, with it, i get error shown in below.
code
// babel.config.js
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
['babel-plugin-styled-components'],
[
'module-resolver',
{
root: ['./src']
},
],
],
};
// in package.json
...
"jest": {
"preset": "react-native",
"verbose": true,
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
}
// App.tsx
import React, { useEffect } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import SplashScreen from 'react-native-splash-screen';
import Profile from './Profile';
const App = () => {
useEffect(() => {
setTimeout(() => {
SplashScreen.hide();
}, 1000);
}, []);
return (
<View style={styles.container}>
<Profile userName={'samslow'} name={'서현석'} />
</View>
);
};
export default App;
same issue
If it is also used on the web, I solved it like this.
import { NativeModules } from "react-native"
const RNSplashScreen = NativeModules.SplashScreen
it occurs in mobile app
I fixed the issue by mocking react-native-splash-screen
into my jest.setup.js
file like so:
jest.mock('react-native-splash-screen', () => {
return {
hide: () => true,
};
});
same issue here. any solutions