NativeBase: Unexpected token import native-base-shoutem-theme/index.js:1

Hi 😉 I have a big problem, I spend all day on fixing that and finding consensus between dependencies of few packages. I have problems with tests:

Users/Pien/Projects/react-native/node_modules/native-base-shoutem-theme/index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import connectStyle from './src/connectStyle';
                                                                                             ^^^^^^
    SyntaxError: Unexpected token import

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
      at Object.<anonymous> (node_modules/native-base/dist/src/index.js:1:1133)
      at Object.<anonymous> (app/index.js:18:96)

For now I searching good version of react, react-native, react-dom, native-base and react-test-renderer. I tried new one and little old one but sometimes I have this error, sometimes others… I decided to fix this one because its problem with some newest version of these. My NPMs:

“babel-cli”: “6.24.1”, “react-native”: “0.44.0”, “native-base”: “2.1.2”, “react”: “16.0.0-alpha.3”, “react-test-renderer”: “16.0.0-alpha.3”

node version 7.7.2 npm version 4.1.2

If you have other WORKING optional versions, please past me these or help fix this error 😉 I thought I will be able to fix it comparing with react-native init, and there tests are working for me but on not on my project… I have no idea what can be wrong 😕

I know it’s little tricky but please help me 😉

EDIT: On version react-native 0.45.0 i have this error 💃

● Test suite failed to run

   TypeError: Cannot read property 'ReactCurrentOwner' of undefined

     at Object.<anonymous> (node_modules/react-native/Libraries/Renderer/src/renderers/shared/ReactGlobalSharedState.js:18:33)
     at Object.<anonymous> (node_modules/react-native/Libraries/Renderer/src/renderers/shared/ReactDebugTool.js:18:1)
     at Object.<anonymous> (node_modules/react-native/Libraries/Renderer/src/renderers/shared/ReactInstrumentation.js:19:20)

My old working versions, but I wanted to upgrade packages:

“babel-cli”: “6.23.0” “react”: “15.4.1”, “react-native”: “0.42.3”, “native-base”: “2.0.12”, “react-addons-test-utils”: “15.4.1”,

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 7
  • Comments: 28 (5 by maintainers)

Commits related to this issue

Most upvoted comments

@Darex1991 @colbywhite @shoutem/theme has been replaced with native-base-shoutem-theme

"jest": {
    "preset": "react-native",
    "transformIgnorePatterns": [
      "node_modules/(?!react-native|native-base-shoutem-theme|@shoutem/animation|@shoutem/ui|tcomb-form-native)"
    ],
    "setupFiles": [
      "./test/setup.js"
    ]
  }

Did you try this

I was able to get my test suite running by piecing together the responses above and in the referenced issue. Folks are correct in suggesting to use tranformIgnorePatterns. However, it seems that you often run into additional problems as you likely have additional libraries installed that must also be included in the list.

So for e.g. in my project, I had to also include “expo” and “react-navigation” in addition to “native-base-shoutem-theme”. Unfortunately I don’t full understand how Jest comes up with the default value for this option (which in my case appeared to work until I started using NativeBase). I would love if anyone could shed some light on this for me!

In summary, I was able to fix my problem with the following change to package.json in my project:

 "jest": {
-  "preset": "jest-expo"
+  "preset": "jest-expo",
+  "transformIgnorePatterns": [
+    "node_modules/(?!react-native|expo|react-navigation|native-base-shoutem-theme|@shoutem/theme|@shoutem/animation|@shoutem/ui|tcomb-form-native)"
+  ]
 },

Which is similar to the above suggestions with the addition of expo|react-navigation| before native-base-shoutem-theme. Would love a better fix that doesn’t require me to manually manage this option for each dependent library! Someone school me 💪

Closing this issue due to inactivity Please reopen this if the issue continues

@lsps9150414 I tried this. Yes it helps with this error, but still, I got few others:

TypeError: window.addEventListener is not a function

      at Object.<anonymous> (node_modules/react-dom/lib/ReactDOMFrameScheduling.js:71:10)
      at Object.<anonymous> (node_modules/react-dom/lib/ReactDOMFiber.js:22:31)
      at Object.<anonymous> (node_modules/react-dom/index.js:3:18)

or

Cannot find module 'react/lib/ReactComponentTreeHook' from 'ReactDebugTool.js'

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:179:17)
      at Object.<anonymous> (node_modules/react-dom/lib/ReactDebugTool.js:16:30)

I’ve been messing around with that here, and I’m now getting the error from my react-native-firebase module instead of from native-base. So basically, the way this is working is that any of the modules inside the rexep pattern (e.g. “…?!react-native|native-base”) would get transpiled so that it understands the ‘import’ command. Thing is, even when I add react-native-firebase to that rexep pattern, I still get the same error. So is Jest not transpiling it? It’s an identical error, the “unexpected token import” one, just now it shows up in the other module. This is what it looks like now. I just kind of added all of the packages relating to firebase to the pattern.

"jest": {
  "preset": "react-native",
  "transformIgnorePatterns": [
      "node_modules/(?!react-native|react-native-firebase|react-native-google-signin|react-native-fbsdk|native-base|native-base-shoutem-theme|@shoutem/theme|@shoutem/animation|@shoutem/ui|tcomb-form-native)"
  ]
}