Nativebase: SyntaxError: Cannot use import statement outside a module

Created on 17 Jan 2020  ·  3Comments  ·  Source: GeekyAnts/NativeBase

I have gone through these following points

Issue Description

● Test suite failed to run

/Users/username/Repos/MyProject/node_modules/native-base-shoutem-theme/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import connectStyle, { clearThemeCache } from "./src/connectStyle";
                                                                                         ^^^^^^

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/native-base/src/index.js:3:1)

node, npm, react-native, react and native-base version, expo version if used, xcode version

"dependencies": {
"native-base": "^2.13.8",
"react": "16.9.0",
"react-native": "0.61.4",
"react-native-image-picker": "^1.1.0",
"react-native-localize": "^1.3.1",
"react-native-multiple-select": "^0.5.5",
"react-native-navigation": "^3.7.0",
"react-native-vector-icons": "^6.6.0",
"react-native-webview": "^8.0.0",
},
"devDependencies": {
"@babel/core": "^7.7.2",
"@babel/runtime": "^7.7.2",
"@react-native-community/eslint-config": "^0.0.5",
"@types/graphql": "^14.5.0",
"@types/jest": "^24.9.0",
"@types/react": "^16.9.11",
"@types/react-native": "^0.60.22",
"@types/react-native-vector-icons": "^6.4.4",
"@types/react-redux": "^7.1.5",
"@types/react-test-renderer": "^16.9.1",
"babel-jest": "^24.9.0",
"eslint": "^6.6.0",
"jest": "^24.9.0",
"metro-react-native-babel-preset": "^0.57.0",
"react-native-typescript-transformer": "^1.2.13",
"react-test-renderer": "16.9.0",
"ts-jest": "^24.3.0",
"typescript": "^3.7.2"
},

Expected behaviour

Passing test processing

Actual behaviour

Gives the error

Most helpful comment

Add transformIgnorePatterns: ['node_modules/(?!(react-native|react-native-button|native-base-.*|react-native-.*)/)'], to jest config :mobile_phone_off:

All 3 comments

Add transformIgnorePatterns: ['node_modules/(?!(react-native|react-native-button|native-base-.*|react-native-.*)/)'], to jest config :mobile_phone_off:

Dear @FDiskas
I did what you said, now getting this:

yarn run v1.22.4
$ jest
 FAIL  __tests__/component.enzyme.test.js
  ● Test suite failed to run

    ReferenceError: __DEV__ is not defined

    > 1 | import 'react-native';
        | ^
      2 | import 'jest-enzyme';
      3 | import Adapter from 'enzyme-adapter-react-16';
      4 | import Enzyme from 'enzyme';

      at Object.<anonymous> (node_modules/react-native/index.js:484:1)
      at Object.<anonymous> (setup-tests.js:1:1)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        2.191 s
Ran all test suites.
error Command failed with exit code 1.

__tests__/component.enzyme.test.js check your file __DEV__ is not defined

Was this page helpful?
0 / 5 - 0 ratings