codler / react-native-keyboard-aware-scroll-view

A ScrollView component that handles keyboard appearance and automatically scrolls to focused TextInput.
https://www.npmjs.com/package/@codler/react-native-keyboard-aware-scroll-view
38 stars 16 forks source link

Cannot use import statement outside a module #3

Closed KovaxG closed 4 years ago

KovaxG commented 4 years ago

Hi, we've recently updated to the latest version of Typescript, and got the following when running tests:

Jest encountered an unexpected token

    This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain 

    By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_mod

    Here's what you can do:
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePa
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/en/configuration.html

    Details:

    /{project}/node_modules/@codler/react-native-keyboard-aware-scroll-view/index.js:3
    import listenToKeyboardEvents from './lib/KeyboardAwareHOC'
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      at Runtime._execModule (node_modules/jest-runtime/build/index.js:1179:56)
      at Object.<anonymous> (node_modules/native-base/src/basic/Content.js:5:1)

We have an indirect dependency to this project via native-base.

KovaxG commented 4 years ago

Sorry, this issue was part of jest, and it had nothing to do with the module, just needed to add this package to transformIgnorePatterns.

jacksonzal commented 4 years ago

Sorry @KovaxG Im just wondering what the rule was the you used I'm trying this in my jest.config.js and its still giving me the same error

module.exports = {
  transformIgnorePatterns: [
      "<rootDir>/node_modules/@codler/react-native-keyboard-aware-scroll-view",
  ],
}
KovaxG commented 4 years ago

Hey, sorry for the late response, here is what we use (with slight modifications)

"transformIgnorePatterns": [
  "/node_modules/(?!(react-native.*|@codler/react-native-keyboard-aware-scroll-view|some-other-stuff)/)"
]