React Native with Typescript and Jest is broken after 0.57 Update: Couldn't find preset “module:metro-react-native-babel-preset” relative to directory

后端 未结 3 690
心在旅途
心在旅途 2021-02-02 14:01

If you integrate test with Jest and Enzyme in the new React Version 0.57 and TypeScript, they won\'t work. Here are the steps to reproduce:

Create a new React Native pro

3条回答
  •  死守一世寂寞
    2021-02-02 14:51

    If I use "presets": ["react-native"] then production/development is broken but tests are working.

    If I use "presets": ["module:metro-react-native-babel-preset"] then tests are broken but production/development is working.

    Not sure why it's like that but a .babelrc solution for me like below works both for development/production and tests. Just add env parameter to your .babelrc file.

    "env": {
        "test": {
            "presets": ["react-native"]
        },
        "production": {
            "presets": ["module:metro-react-native-babel-preset"]
        },
        "development": {
            "presets": ["module:metro-react-native-babel-preset"]
        }
    }
    

提交回复
热议问题