magicismight / static-container

MIT License
7 stars 6 forks source link

Jest encountered an unexpected token #3

Open yuheidapperapps opened 5 years ago

yuheidapperapps commented 5 years ago

● Test suite failed to run

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 JavaScript.

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

Here's what you can do:
 • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
 • 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 "moduleNameMapper" config option.

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

Details:

/Users/AppLabs1/Documents/Apps/rent-react-native/node_modules/static-container/StaticContainer.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import React, { Component, Children } from 'react';
                                                                                         ^^^^^^

SyntaxError: Unexpected token import

  at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
  at Object.<anonymous> (node_modules/react-native-general-siblings/index.js:24:47)
  at Object.<anonymous> (node_modules/react-native-popup-dialog/dist/PopupDialog.js:43:35)

version: 1.2.0 jest: 23.6.0

peterh32 commented 5 years ago

I was able to resolve this by adding this to the Jest configuration in my project's package.json:

        "transformIgnorePatterns": [
            "node_modules/(?!static-container)/"
        ]

See more at https://jestjs.io/docs/en/configuration.html#transformignorepatterns-array-string