react-native-paper icon indicating copy to clipboard operation
react-native-paper copied to clipboard

Cannot use import statement outside a module

Open koutilyagurjikindi opened this issue 6 years ago • 7 comments

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.":function(module,exports,require,__dirname,__filename,global,jest){import React, { Component } from 'react';

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: [ '/node_modules/react-native-gesture-handler/jestSetup.js', '/node_modules/appcenter/test/AppCenterMock.js', '/node_modules/appcenter-analytics/test/AppCenterAnalyticsMock.js', '/node_modules/appcenter-crashes/test/AppCenterCrashesMock.js', ], testPathIgnorePatterns: ['/node_modules'], transformIgnorePatterns: [ 'node_modules/(?!(react-native' + '|react-native-cookies' + '|@sentry/react-native' + '|react-native-safe-area-view' + ')/)', ], collectCoverage: true, };

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

koutilyagurjikindi avatar Jun 17 '20 08:06 koutilyagurjikindi

Please help me to solve this error

koutilyagurjikindi avatar Jun 17 '20 08:06 koutilyagurjikindi

I had issues like this previously. Usually it was solved by mocking in a jest setup file

vamshi9666 avatar Jun 23 '20 19:06 vamshi9666

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.

github-actions[bot] avatar Aug 23 '20 00:08 github-actions[bot]

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

DiegoBM avatar Sep 20 '21 13:09 DiegoBM

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?

rafaelbpa avatar Jan 23 '22 16:01 rafaelbpa

Same issue here. add react-native-paper, and jest stop

JossanPetrenko avatar Feb 07 '22 18:02 JossanPetrenko

Ensure you have your transformIgnorePatterns setup correctly in package.json or jest.config.js

jacquesdev avatar Jul 20 '23 21:07 jacquesdev