Cannot use import statement outside a module
when I am running the npm test it showing this error in react native paper/react-native safe area view
Current behaviour
● Test suite failed to run
node_modules/react-native-paper/node_modules/react-native-safe-area-view/index.js:1
({"Object.
SyntaxError: Cannot use import statement outside a module
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> (node_modules/react-native-paper/lib/commonjs/components/BottomNavigation.tsx:17:1)
Test Suites: 1 failed, 1 passed, 2 total
Expected behaviour
Code sample
jest file
module.exports = {
// your Jest test options
displayName: 'test',
preset: 'react-native',
transform: {
'^.+\.(js)$': require.resolve('react-native/jest/preprocessor.js'),
},
setupFiles: [
'
Screenshots (if applicable)
What have you tried
Your Environment
| software | version |
|---|---|
| ios or android | |
| react-native | |
| react-native-paper | |
| node | |
| npm or yarn | |
| expo sdk |
Please help me to solve this error
I had issues like this previously. Usually it was solved by mocking in a jest setup file
Hello 👋, this issue has been open for more than 2 months with no activity on it. If the issue is still present in the latest version, please leave a comment within 7 days to keep it open, otherwise it will be closed automatically. If you found a solution on workaround for the issue, please comment here for others to find. If this issue is critical for you, please consider sending a pull request to fix the issue.
Same issue here. The minute I include and start using react-native-paper, Jest will start throwing a similar error message to the one above
Any news about this? I'm with the same problem.
How this nice library doesn't work with jest? Or if does, there's no documentation about it. Anyone here can help?
Same issue here. add react-native-paper, and jest stop
Ensure you have your transformIgnorePatterns setup correctly in package.json or jest.config.js