Jest fails with “Unexpected token *” on import statement

前端 未结 5 647
南旧
南旧 2021-02-03 18:15

Why does Jest fail with \"Unexpected token *\" on a simple import statement...

Error log:

Admin@Admin-PC MINGW32 /d/project (master)
$ npm         


        
5条回答
  •  無奈伤痛
    2021-02-03 18:41

    As it has been said, some modules needs to be transpiled, & some don't. Here is a regex I use that work in a lot of projects

      "jest": {
        "preset": "react-native",
        "transformIgnorePatterns": [
          "node_modules/(?!(jest-)?react-native|react-(native|universal|navigation)-(.*)|@react-native-community/(.*)|@react-navigation/(.*)|bs-platform|(@[a-zA-Z]+/)?(bs|reason|rescript)-(.*)+)"
        ]
      }
    

    It's working for most common react native thing, & include also a specific package (here bs-platform) as an example, when isn't captured by previous patterns.

提交回复
热议问题