简体   繁体   English

Jest React Native Expo.fx.js 遇到了意外的令牌

[英]Jest React Native Expo.fx.js encountered an unexpected token

This is from the boilerplate Expo app built with create-react-native-app这是来自使用create-react-native-app构建的样板Expo应用程序

Here's the jest section of my package.json :这是我的package.json笑话部分:

  "jest": {
    "preset": "react-native",
    "testEnvironment": "node"
  },

Here's the output when I attempt to run jest :这是我尝试运行jest时的 output :

> jest

 FAIL  src/__tests__/App.js
  ● 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:

    /home/charney/om/star-harvester-centauri/node_modules/expo/build/Expo.fx.js:1
    import './environment/react-native-logs.fx';
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      at Runtime._execModule (node_modules/jest-runtime/build/index.js:1157:58)
      at Object.<anonymous> (node_modules/expo/src/Expo.ts:1:1)

Same answer as Jest encountered an unexpected token with react-nativeJest 遇到的意外令牌相同的答案是 react-native

  "jest": {
    "preset": "react-native",
    "transform": {
      "^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"    },
    "testEnvironment": "node"
  },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM