Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6581

Invariant Violation: __fbBatchedBridgeConfig is not set, cannot invoke native modules

$
0
0

I am getting he following error when running a jest test:● Test suite failed to run

Invariant Violation: __fbBatchedBridgeConfig is not set, cannot invoke native modules  1 | import { Platform } from "react-native";> 2 | import env from "react-native-config";    | ^  3 |  4 | // const env = require("react-native-config").default;  5 |  at invariant (node_modules/invariant/invariant.js:40:15)  at Object.invariant (node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:181:3)  at Object.require [as NativeModules] (node_modules/react-native/index.js:386:12)  at Object.NativeModules (node_modules/react-native-config/index.js:8:16)  at Object.<anonymous> (config.js:2:1)  at Object.<anonymous> (src/localization/I18n.js:14:1)  at Object.<anonymous> (src/utils/CommonUtils.js:3:1)  at Object.<anonymous> (src/localDB/Config.js:18:1)  at Object.<anonymous> (src/modules/trust/__tests__/unit/TrustHeading.test.js:1:1)  at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)  at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:9)

My config files for jest, babel and typescript are as follows:

jest.config.js

/** * For a detailed explanation regarding each configuration property, visit: * https://jestjs.io/docs/configuration *//** @type {import('jest').Config} */const config = {  clearMocks: true,  collectCoverage: true,  // A set of global variables that need to be available in all test environments  globals: {    __DEV__: true,  },  // An array of file extensions your modules use  moduleFileExtensions: ["js", "jsx", "ts", "tsx", "json"],  // The glob patterns Jest uses to detect test files  testMatch: ["**/__tests__/unit/*.test.js",  ],  transformIgnorePatterns: [],};module.exports = config;

tsconfig.json

{"compilerOptions": {"target": "ES6","module": "CommonJS","baseUrl": ".","paths": {"@*": ["src/*"],"sample-mobile/*": ["./*"],"react": ["./node_modules/@types/react"]    },    // This flag is required to be true because of moment.js"esModuleInterop": true  },"extends": "@tsconfig/react-native/tsconfig.json","exclude": ["node_modules"]}

babel.config.js

module.exports = params => {  const isTest = params.env("test");  const config = {    presets: ["module:metro-react-native-babel-preset",      ["@babel/preset-env", { targets: { node: "current", esmodules: true } }],    ],    plugins: ["react-native-reanimated/plugin","remove-test-ids",      ["@babel/plugin-proposal-class-properties", { loose: true }],      ["@babel/plugin-proposal-private-property-in-object", { loose: true }],    ],  };  if (isTest) {    config.plugins.push(["@babel/plugin-proposal-private-methods",      {        loose: true,      },    ]);  }  return config;};

package.json

"dependencies": {"@bam.tech/react-native-image-resizer": "^3.0.4","@notifee/react-native": "^5.6.0","@react-native-async-storage/async-storage": "^1.17.10","@react-native-community/art": "^1.2.0","@react-native-community/cli-platform-android": "^9.0.0","@react-native-community/cli-platform-ios": "^9.0.0","@react-native-community/clipboard": "^1.5.1","@react-native-community/datetimepicker": "^2.6.2","@react-native-community/hooks": "^2.8.1","@react-native-community/netinfo": "^9.3.0","@react-native-community/push-notification-ios": "^1.10.1","@react-native-community/toolbar-android": "^0.2.1","@react-native-firebase/app": "^18.0.0","@react-native-firebase/messaging": "^18.0.0","@react-native-masked-view/masked-view": "^0.2.7","@react-native-picker/picker": "^2.4.4","@react-navigation/bottom-tabs": "^5.11.15","@react-navigation/drawer": "^5.x","@react-navigation/material-top-tabs": "^6.5.3","@react-navigation/native": "^5.9.8","@react-navigation/stack": "^5.14.9","@realm/react": "^0.4.3","@reduxjs/toolkit": "^1.8.5","@rneui/base": "^4.0.0-rc.7","@rneui/themed": "^4.0.0-rc.7","@sentry/react-native": "^4.10.1","amazon-cognito-identity-js": "^5.2.10","appcenter-cli": "^2.14.0","aws-amplify": "^4.3.33","aws-amplify-react-native": "^6.0.5","axios": "^1.3.5","buffer": "^5.7.1","camelcase-keys": "^6.2.1","color": "^3.2.1","countries-list": "^2.6.1","crypto-js": "^4.1.1","deprecated-react-native-prop-types": "^2.3.0","expo": "^47.0.0","expo-file-system": "~14.1.0","expo-secure-store": "~11.3.0","file-type": "^14.7.1","formik": "^2.2.9","hermes-engine": "^0.10.0","rn-tourguide": "^3.4.1","humanize-string": "^2.1.0","i18n-iso-countries": "^6.8.0","i18next": "^21.9.2","i18next-v4-format-converter": "^1.0.3","iban": "0.0.14","intl-pluralrules": "^1.3.1","jest-date-mock": "^1.0.8","libphonenumber-js": "^1.10.13","lodash.flatmapdeep": "^4.10.0","lodash.range": "^3.2.0","lodash.truncate": "^4.4.2","lottie-ios": "3.4.0","lottie-react-native": "^5.1.4","mime-types": "^2.1.35","moment": "^2.29.4","moment-timezone": "^0.5.43","no-case": "^3.0.4","numeral": "^2.0.6","ordinal": "^1.0.3","path": "^0.12.7","qs": "^6.11.0","ramda": "^0.27.2","react": "^18.2.0","react-i18next": "^11.18.6","react-native": "^0.71.0","react-native-adjust": "^4.35.1","react-native-appboy-sdk": "^1.41.0","react-native-background-fetch": "^4.1.5","react-native-biometrics": "^2.2.0","react-native-blob-util": "^0.19.1","react-native-bootsplash": "^5.3.0","react-native-branch": "^5.5.0","react-native-camera-kit": "^13.0.0","react-native-circular-progress-indicator": "^4.4.0","react-native-code-push": "7.1.0","react-native-config": "^0.12.0","react-native-copilot": "^3.2.1","react-native-dashed-line": "^1.1.0","react-native-device-info": "^10.8.0","react-native-drop-shadow": "^0.0.7","react-native-gesture-handler": "^2.6.0","react-native-image-crop-picker": "^0.38.1","react-native-input-scroll-view": "^1.11.0","react-native-linear-gradient": "^2.6.2","react-native-mmkv": "^2.12.1","react-native-modal-datetime-picker": "^14.0.0","react-native-otp-verify": "^1.1.8","react-native-pager-view": "^6.1.2","react-native-pdf": "^6.7.1","react-native-permissions": "^3.6.1","react-native-reanimated": "^2.17.0","react-native-responsive-screen": "^1.4.2","react-native-restart": "^0.0.22","react-native-safe-area-context": "^3.4.1","react-native-screens": "^2.18.1","react-native-select-dropdown": "^3.3.2","react-native-share": "^8.2.2","react-native-snap-carousel": "^4.0.0-beta.5","react-native-svg": "^13.2.0","react-native-svg-transformer": "^1.0.0","react-native-tab-view": "^2.16.0","react-native-text-input-mask": "3.2.0","react-native-vector-icons": "^9.2.0","react-native-version-info": "^1.1.1","react-native-view-shot": "^3.6.0","react-native-walkthrough-tooltip": "^1.4.0","react-native-webview": "^11.23.0","react-native-youtube-iframe": "^2.3.0","react-native-zendesk-chat": "^0.4.1","react-query": "^3.39.3","react-redux": "^7.2.8","realm": "11.5.1","reanimated-bottom-sheet": "^1.0.0-alpha.22","redux": "^4.2.0","redux-actions": "^2.6.5","redux-persist": "^6.0.0","reselect": "^4.1.6","round-half-even": "^1.3.0","round-to": "^6.0.0","simple-credit-card-input": "^0.4.2","simple-pincode-input": "^1.1.2","snakecase-keys": "^5.4.2","title-case": "^3.0.3","url-parse": "^1.5.10","use-deep-compare": "^1.1.0","v8-android-jit-nointl": "^9.93.0","victory-native": "^36.6.8","yup": "^0.28.5"  },"devDependencies": {"@babel/core": "^7.20.0","@babel/eslint-parser": "^7.19.1","@babel/plugin-proposal-private-methods": "^7.18.6","@babel/preset-env": "^7.20.0","@babel/runtime": "^7.20.0","@faker-js/faker": "^7.6.0","@jest/globals": "^29.7.0","@react-native-community/eslint-config": "^3.1.0","@storybook/addon-actions": "^5.3.21","@storybook/addon-links": "^5.3.21","@storybook/addon-ondevice-actions": "^5.3.23","@storybook/addons": "^5.3.22","@storybook/react-native": "^5.3.25","@storybook/react-native-server": "5.3.19","@testing-library/jest-native": "^5.4.2","@testing-library/react-hooks": "^8.0.1","@testing-library/react-native": "^12.1.2","@trivago/prettier-plugin-sort-imports": "^3.3.0","@tsconfig/react-native": "^3.0.3","@types/jest": "^29.5.11","@types/react": "^18.2.0","@types/react-test-renderer": "^18.0.7","@typescript-eslint/eslint-plugin": "^5.13.0","@typescript-eslint/parser": "^5.0.0","babel-jest": "^29.2.1","babel-loader": "^8.2.5","babel-plugin-remove-test-ids": "^1.1.0","detox": "^20.1.3","detox-recorder": "^1.0.151","eslint": "8.47.0","eslint-config-airbnb": "^19.0.4","eslint-config-airbnb-typescript": "^17.1.0","eslint-config-prettier": "^8.5.0","eslint-plugin-import": "^2.29.1","eslint-plugin-jest": "^27.0.4","eslint-plugin-jsx-a11y": "^6.8.0","eslint-plugin-prettier": "^4.2.1","eslint-plugin-react": "^7.31.8","eslint-plugin-react-hooks": "^4.6.0","eslint-plugin-react-native": "^4.0.0","eslint-plugin-unused-imports": "^2.0.0","husky": ">=7","jest": "^29.2.1","metro-react-native-babel-preset": "^0.73.7","prettier": "^2.7.1","pretty-quick": "^2.0.2","react-dom": "^16.14.0","react-native-storybook-loader": "^1.8.1","react-test-renderer": "18.2.0","reactotron-react-native": "^5.0.3","reactotron-redux": "^3.1.3","ts-jest": "^29.1.2","typescript": "5.1.6"  }

I searched for it and found these articles but none of them solve the issue for me. I feel like there might be some mismatch for between the configs, but I am not able to point out what.

React-Native debugging: Failed to print error: Requiring module .... threw an exception: Invariant Violation: __fbBatchedBridgeConfig is not set,fbBatchedBridgeConfig is not set when running jest tests.

Any help in this matter will be greatly appreciated


Viewing all articles
Browse latest Browse all 6581

Latest Images

Trending Articles



Latest Images