react-native cannot read property 'bindings' of null - react-native

I tried to run a react-native simulator.
However, this error came out in the simulator:
Failed to load bundle(http://localhost:8081/index.bundle?
platform=ios&dev=true&minify=false)
with error:(/Users/sugawarasyuta/Desktop/albums/index.js:
Cannot read property 'bindings' of null(null))
I double‐checked my code syntax. But I feel like this is not about that. Do you know how to solve this error?
Here are my files:
index.js
import React from 'react';
import { AppRegistry,View } from 'react-native';
import Header from './src/components/header';
import AlbumList from './src/components/AlbumList';
//Create a component
const App = () => (
<View>
<Header headerText= {'albums'} />
<AlbumList />
</View>
);
AppRegistry.registerComponent('albums', () => App );
AlbumList.js
import React,{Component}from 'react';
import {View, Text} from 'react-native';
import axios from 'axios';
class AlbumList extends Component {
componentWillMount(){
axios.get('https://rallycoding.herokuapp.com/api/music_albums')
.then(response => console.log(response));
}
render(){
return(
<View>
<Text>AlbumList!!!</Text>
</View>
);
}
}
export default AlbumList;
These are terminal statements:
/usr/bin/codesign --force --sign - --entitlements /Users/sugawarasyuta/Desktop/albums/ios/build/Build/Intermediates.noindex/albums.build/Debug-iphonesimulator/albums.build/albums.app.xcent --timestamp=none /Users/sugawarasyuta/Desktop/albums/ios/build/Build/Products/Debug-iphonesimulator/albums.app
/Users/sugawarasyuta/Desktop/albums/ios/build/Build/Products/Debug-iphonesimulator/albums.app: resource fork, Finder information, or similar detritus not allowed
Command /usr/bin/codesign failed with exit code 1
** BUILD FAILED **
The following build commands failed:
CodeSign build/Build/Products/Debug-iphonesimulator/albums.app
(1 failure)
Installing build/Build/Products/Debug-iphonesimulator/albums.app
Launching org.reactjs.native.example.albums
org.reactjs.native.example.albums: 8385
This is my package.json. Are those dependencies correct?
{
"name": "albums",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"axios": "^0.18.0",
"babel-plugin-transform-es2015-arrow-functions": "^6.22.0",
"react": "16.3.1",
"react-native": "^0.56.0"
},
"devDependencies": {
"#babel/preset-env": "^7.0.0-beta.53",
"babel-jest": "23.0.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react-native": "4.0.0",
"eslint-config-rallycoding": "^3.2.0",
"jest": "23.1.0",
"react-test-renderer": "16.3.1"
},
"jest": {
"preset": "react-native"
}
}
I upgraded "babel-preset-react-native" from "4.0.0" to "^5.0.1" and another error came out:
error: bundling failed: SyntaxError:
/Users/sugawarasyuta/Desktop/albums/index.js: Unexpected token (11:3)
10 | const App = () => {
> 11 | <Header headerText= {'albums'} />
| ^
12 |
13 | };
at Parser.raise
(/Users/sugawarasyuta/Desktop/albums/node_modules
/#babel/core/node_modules/babylon/lib/index.js:776:15)
at Parser.unexpected
(/Users/sugawarasyuta/Desktop/albums/node_modules/
#babel/core/node_modules/babylon/lib/index.js:2079:16)
at Parser.parseExprAtom (/Users/sugawarasyuta/Desktop/albums/node_modules/#babel/core/node_modules/babylon/lib/index.js:3157:20)
at Parser.parseExprSubscripts (/Users/sugawarasyuta/Desktop/albums/node_modules/#babel/core/node_modules/babylon/lib/index.js:2757:21)
at Parser.parseMaybeUnary (/Users/sugawarasyuta/Desktop/albums/node_modules/#babel/core/node_modules/babylon/lib/index.js:2736:21)
at Parser.parseExprOps (/Users/sugawarasyuta/Desktop/albums/node_modules/#babel/core/node_modules/babylon/lib/index.js:2643:21)
at Parser.parseMaybeConditional (/Users/sugawarasyuta/Desktop/albums/node_modules/#babel/core/node_modules/babylon/lib/index.js:2615:21)
at Parser.parseMaybeAssign (/Users/sugawarasyuta/Desktop/albums/node_modules/#babel/core/node_modules/babylon/lib/index.js:2562:21)
at Parser.parseExpression (/Users/sugawarasyuta/Desktop/albums/node_modules/#babel/core/node_modules/babylon/lib/index.js:2515:21)
at Parser.parseStatementContent (/Users/sugawarasyuta/Desktop/albums/node_modules/#babel/core/node_modules/babylon/lib/index.js:4076:21)
BUNDLE [ios, dev] ../../index.js ░░░░░░░░░░░░░░░░ 0.0% (0/1), failed.
I feel like this is not because of syntax error simply, but cause of dependencies. Do you know how can I fix it?

Without any further information, I suspect you need to update babel-preset-react-native.
When upgrading to 0.56, make sure to bump your
babel-preset-react-native package.json dependency to ^5.0.1 or newer.
https://github.com/facebook/react-native/releases

For React Native 0.57
When upgrading to React Native 0.57, follow these steps to fix this issue:
Upgrade the version of React in the package.json to 16.5
Change the babel-preset dependency from "babel-preset-react-native": "^5" to "metro-react-native-babel-preset": "^0.45.0"
Change the .babelrc configuration to:
{
"presets": ["module:metro-react-native-babel-preset"]
}
Run rm -rf node_modules/ to remove your old modules
Run npm install to get a fresh node_modules/
Run react-native upgrade to upgrade your config files
Run rm -rf android/build/ ios/build/ to get rid of your old compiled apps
Run your app again, it should work!
Source for the first steps

REACT NATIVE 0.57 FRESH INSTALLS iOS ANDROID
I did a fresh install of react native from react-native init projectName
The package.json
{
"name": "JesteeTestee",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "^16.5.2",
"react-native": "0.57.4"
},
devDependencies": {
"babel-jest": "23.6.0",
"jest": "23.6.0",
"metro-react-native-babel-preset": "^0.47.0",
"react-test-renderer": "16.6.0-alpha.8af6728"
},
"jest": {
"preset": "react-native",
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
}
}
}
As you can see it is the latest, current version of RN#0.57.4 and metro-react-native-babel-preset#0.47.0.
Also the default .babelrc
{
"presets": ["module:metro-react-native-babel-preset"]
}
Simply added the following to the Jest part of the package.json;
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
}
Given the hours I spent finding this today, if you are doing a fresh install and hit a snag just delete the project, start again and try this simple step only.
Tested for react-native run-ios and run-android.

FOR REACT-NATIVE VERSION 0.57 OR MORE
On babel.config.js, simply change presets as below
"presets": ["module:metro-react-native-babel-preset"]
This worked for me after trying many different solutions

Related

"SyntaxError: Cannot use import statement outside a module" error while testing React Native project with Jest and #testing-library/react-native?

Error I'm getting Anytime I run npm test:
FAIL ./App.test.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:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/en/ecmascript-modules for how to enable it.
• 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/bestes/Desktop/react-native-training/node_modules/react-native-status-bar-height/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { Dimensions, Platform, StatusBar } from 'react-native';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
at Object.<anonymous> (node_modules/react-native-elements/src/config/index.js:1:1)
My Test:
import 'react-native';
import React from 'react';
import { render } from '#/../testing/test-utils'
import App from './App'
test('should render app component', () => {
const result = render(<App />)
expect(result).toMatchSnapshot()
})
My test-utils.js file:
import React from 'react'
import { render } from '#testing-library/react-native'
import { store } from '#/bootstrap/redux'
import { Provider } from 'react-redux'
const AllTheProviders = ({ children }) => {
return (
<Provider store={store}>
{children}
</Provider>
)
}
const customRender = (ui, options) =>
render(ui, { wrapper: AllTheProviders, ...options })
// re-export everything
export * from '#testing-library/react-native'
// override render method
export { customRender as render }
My package.json file:
{
"name": "ReactNativeTraining",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"#react-native-community/geolocation": "2.0.2",
"#react-native-community/masked-view": "0.1.10",
"#react-native-picker/picker": "1.9.10",
"#reduxjs/toolkit": "1.5.0",
"axios": "0.21.1",
"dayjs": "1.10.4",
"lodash": "4.17.20",
"react": "16.13.1",
"react-native": "0.63.2",
"react-native-config": "1.4.2",
"react-native-elements": "3.0.0-alpha.1",
"react-native-geocoding": "0.5.0",
"react-native-gesture-handler": "1.9.0",
"react-native-permissions": "3.0.0",
"react-native-picker-select": "8.0.4",
"react-native-reanimated": "1.13.2",
"react-native-safe-area-context": "3.1.9",
"react-native-screens": "2.17.0",
"react-native-size-matters": "0.4.0",
"react-native-vector-icons": "8.0.0",
"react-navigation": "4.0.2",
"react-navigation-stack": "1.5.4",
"react-navigation-tabs": "2.4.1",
"react-redux": "7.2.2"
},
"devDependencies": {
"#babel/core": "7.12.10",
"#babel/runtime": "7.12.5",
"#react-native-community/eslint-config": "2.0.0",
"#testing-library/jest-native": "4.0.1",
"#testing-library/react-native": "7.2.0",
"babel-jest": "^26.6.3",
"babel-plugin-module-resolver": "4.0.0",
"eslint": "7.18.0",
"jest": "26.6.3",
"metro-react-native-babel-preset": "0.64.0",
"react-test-renderer": "16.13.1"
},
"type": "module",
"jest": {
"verbose": true,
"preset": "react-native",
"setupFilesAfterEnv": ["#testing-library/jest-native/extend-expect"],
"transformIgnorePatterns": [
"node_modules/(?!(react-native",
"#react-native-community/geolocation",
"#react-native-community/masked-view",
"|#react-native-picker/picker",
"|#reduxjs/toolkit",
"|axios",
"|dayjs",
"|lodash",
"|react",
"|react-native",
"|react-native-config",
"|react-native-elements",
"|react-native-geocoding",
"|react-native-gesture-handler",
"|react-native-permissions",
"|react-native-picker-select",
"|react-native-reanimated",
"|react-native-safe-area-context",
"|react-native-screens",
"|react-native-size-matters",
"|react-native-vector-icons",
"|react-navigation",
"|react-navigation-stack",
"|react-navigation-tabs",
"|react-redux",
")/)"
]
}
}
My babel.config.js file:
module.exports = function (api) {
api.cache(true)
const presets = [
'module:metro-react-native-babel-preset'
]
const plugins = [
[
'module-resolver', {
'root': ['./src/'],
'extensions': ['.js', '.ios.js', '.android.js'],
'alias': {
'#': './src/'
}
}
]
]
return {
presets,
plugins
}
}
What I've tried:
Adding "type": "module" to my root level package.json file, which fixed a similar error with exporting,
Adding Transform Ignore Patterns to the Jest key in the package.json file.
I'd added ALL of my dependencies to the transformIgnorePatterns as it kept throwing errors on each one, until I added all and now it throws on react-native modules imports.
[Solved] Work for me
Install below
npm install --save-dev #babel/core
npm install --save-dev #babel/preset-env
after that create the "babel.config.js" file in the root and that content should be as below
module.exports = {
presets: ['#babel/preset-env', '#babel/preset-react'],
env: {
test: {
plugins: ["#babel/plugin-transform-runtime"]
}
}
};

React Native tests failing, missing babel transforms

I want to test a React Native application that I've created based on the default guides, so it's very simple and has not had any changes w.r.t. the initial test configuration. The only difference seems to be that it's using npm instead of yarn (so it has a package-lock.json).
Here is the package.json:
{
"name": "foo",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"react": "16.9.0",
"react-native": "0.61.5",
"react-native-gesture-handler": "^1.5.2",
"react-navigation": "^4.0.10",
"react-navigation-stack": "^1.10.3"
},
"devDependencies": {
"#babel/core": "^7.7.4",
"#babel/runtime": "^7.7.4",
"#react-native-community/eslint-config": "^0.0.5",
"babel-jest": "^24.9.0",
"eslint": "^6.7.1",
"jest": "^24.9.0",
"license-checker": "^25.0.1",
"metro-react-native-babel-preset": "^0.57.0",
"react-test-renderer": "16.9.0"
},
"jest": {
"preset": "react-native"
}
}
The test file __tests__/App-test.js is very simple (and auto-generated):
import 'react-native';
import React from 'react';
import App from '../App';
// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';
it('renders correctly', () => {
renderer.create(<App />);
});
I get this error:
➜ npm test
> jest
FAIL __tests__/App-test.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:
/node_modules/#foo/bar/src/main.js:24
export function milliseconds(timeoutInMilliseconds) {
^^^^^^
SyntaxError: Unexpected token 'export'
Now, I don't really understand why it wouldn't work "out of the box". Other guides mention the same steps, too.
Adding a .babelrc with:
{
"presets": ["react-native"]
}
produces the error:
Cannot find module 'babel-preset-react-native' from '/'
- If you want to resolve "react-native", use "module:react-native"
at Function.module.exports [as sync] (node_modules/resolve/lib/sync.js:74:15)
at resolveStandardizedName (node_modules/#babel/core/lib/config/files/plugins.js:101:31)
at resolvePreset (node_modules/#babel/core/lib/config/files/plugins.js:58:10)
at loadPreset (node_modules/#babel/core/lib/config/files/plugins.js:77:20)
at createDescriptor (node_modules/#babel/core/lib/config/config-descriptors.js:154:9)
at node_modules/#babel/core/lib/config/config-descriptors.js:109:50
at Array.map (<anonymous>)
at createDescriptors (node_modules/#babel/core/lib/config/config-descriptors.js:109:29)
at createPresetDescriptors (node_modules/#babel/core/lib/config/config-descriptors.js:101:10)
at presets (node_modules/#babel/core/lib/config/config-descriptors.js:47:19)
There is already a babel.config.js file with the following contents (as suggested here):
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
};
What should I do? I've seen this question but the React App has not been upgraded and is not missing anything, AFAICT. Note that when I create a completely new app with the init script, the tests run fine.
You are using "react-navigation": "^4.0.10" which uses react-native-gesture-handler. Jest does not know about it. You have to mock react-native-gesture-handler and add react-navigation to transformIgnorePatterns or use react-native-jest-mocks.
Some examples of mocking react-native-gesture-handler can be found here: https://github.com/software-mansion/react-native-gesture-handler/issues/344
Add "files": ["jest/setup.js"]," inside package.json. Also transformIgnorePatterns must include react-navigation-stack, #react-native-community, react-native-gesture-handler and react-navigation.
package.json:
"files": [
"jest/setup.js"
],
"jest": {
"preset": "react-native",
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
},
"setupFiles": ["./jest/setup.js"],
"testPathIgnorePatterns": [
"/node_modules/"
],
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?react-native|react-navigation-stack|#react-native-community|react-native-gesture-handler|react-navigation|#react-navigation/.*)"
]
}
jest/setup.js:
import { NativeModules as RNNativeModules } from "react-native";
RNNativeModules.UIManager = RNNativeModules.UIManager || {};
RNNativeModules.UIManager.RCTView = RNNativeModules.UIManager.RCTView || {};
RNNativeModules.RNGestureHandlerModule = RNNativeModules.RNGestureHandlerModule || {
State: { BEGAN: "BEGAN", FAILED: "FAILED", ACTIVE: "ACTIVE", END: "END" },
attachGestureHandler: jest.fn(),
createGestureHandler: jest.fn(),
dropGestureHandler: jest.fn(),
updateGestureHandler: jest.fn(),
};
RNNativeModules.PlatformConstants = RNNativeModules.PlatformConstants || {
forceTouchAvailable: false
};
jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper');
Now run jest and it should pass the test. I have created a repo with an example RN 0.61 app using react-navigation that has jest test passing: https://github.com/clytras/RNJestTest
Or you can try react-native-jest-mocks but I haven't tried it with RN 0.61 yet.

How to get rid of SyntaxError: Unexpected Token { when trying to test a React-Native with a Mapbox in Jest?

I've tried quite a few variations on this with no luck.
Situation: I want to render a React Native app that has a Mapbox map in it inside my Jest tests, so I can test the logic we wrote around it.
I've managed to reproduce the error I'm seeing in a mini repo: https://github.com/JKowalsky/mapbox-error-test-repo/tree/master
The mini repo is a react-native init default project that includes Mapbox and sets an access token, just so we can play with the dependency.
import MapboxGL from '#react-native-mapbox-gl/maps';
MapboxGL.setAccessToken('fakeyfakeytokentoken');
I'd expect the default __test__/App-test.js to still run, but it fails on the Mapbox include. It looked like a Babel problem, so I set up the following babel.config.js;
module.exports = function(api) {
api.cache(true);
return {
presets: [
'module:metro-react-native-babel-preset',
"#babel/preset-env",
"#babel/preset-flow"
],
plugins: [
"#babel/plugin-proposal-class-properties",
"#babel/plugin-syntax-dynamic-import"
]
};
};
And here's the package.json to run that:
{
"name": "mapboxerror",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest --no-cache",
"lint": "eslint ."
},
"dependencies": {
"#mapbox/geo-viewport": "^0.4.0",
"#react-native-mapbox-gl/maps": "^7.0.6",
"jsdom": "^15.1.1",
"mapbox": "^1.0.0-beta10",
"react": "16.9.0",
"react-native": "0.61.1"
},
"devDependencies": {
"#babel/core": "^7.6.2",
"#babel/plugin-proposal-class-properties": "^7.5.5",
"#babel/plugin-syntax-dynamic-import": "^7.2.0",
"#babel/preset-env": "^7.6.2",
"#babel/preset-flow": "^7.0.0",
"#babel/runtime": "^7.6.2",
"#react-native-community/eslint-config": "^0.0.5",
"babel-jest": "^24.9.0",
"eslint": "^6.4.0",
"jest": "^24.9.0",
"metro-react-native-babel-preset": "^0.56.0",
"react-test-renderer": "16.9.0"
},
"jest": {
"preset": "react-native"
}
}
I still get the unexpected token error:
/Users/jennifer/dev/mapbox-error-test-repo/node_modules/#react-native-mapbox-gl/maps/javascript/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import {Animated, NativeModules, PermissionsAndroid} from 'react-native';
SyntaxError: Unexpected token {
25 | } from 'react-native/Libraries/NewAppScreen';
26 |
> 27 | import MapboxGL from '#react-native-mapbox-gl/maps';
| ^
28 | MapboxGL.setAccessToken('fakeyfakeytokentoken');
29 |
30 | const App: () => React$Node = () => {
at ScriptTransformer._transformAndBuildScript (node_modules/#jest/transform/build/ScriptTransformer.js:537:17)
at ScriptTransformer.transform (node_modules/#jest/transform/build/ScriptTransformer.js:579:25)
at Object.<anonymous> (App.js:27:1)
Final curiosity: I've added a transform inside the jest config in package.json, but it then gives me a type error (this is not a typescript project.)
"jest": {
"preset": "react-native",
"transformIgnorePatterns": [
"node_modules/(?!(mapbox-gl|mapbox|#react-native-mapbox-gl))/"
]
}
Doing that gives me this error which is even more inscrutable:
yarn run v1.16.0
$ jest --no-cache
FAIL __tests__/App-test.js
● Test suite failed to run
TypeError: (0 , _typeof4.default) is not a function
at _typeof2 (node_modules/#babel/runtime/helpers/typeof.js:8:63)
at _typeof (node_modules/#babel/runtime/helpers/typeof.js:22:39)
at new Promise (node_modules/promise/lib/core.js:44:31)
at valuePromise (node_modules/promise/lib/es6-extensions.js:18:11)
at Object.<anonymous> (node_modules/promise/lib/es6-extensions.js:10:12)
at Object.<anonymous> (node_modules/promise/lib/index.js:9:1)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.192s
Ran all test suites.
error Command failed with exit code 1.
Any hints? I've been circling this issue for a while, and there isn't a ton of testing infrastructure support for Mapbox.
Alright, I actually managed to get this working. I had to mock both the Mapbox-gl and react-native EventEmitter dependencies in addition to adding a ton of babel transforms. The linked repository has been updated with a now passing unit test.

React Select IE 11 - TypeError: Object doesn't support property or method 'assign'

What is wrong with this code ...IE 11 throwing
TypeError: Object doesn't support property or method 'assign'...chrome is behaving fine
import React from 'react';
import Select,{components} from 'react-select';
import { colourOptions } from '../react-select_Samples/data.js';
const Option = props => {
return ( <div>
<components.Option {...props}><input type="checkbox" checked={props.isSelected} onChange={() => null} />{props.label}
</components.Option></div> );
};
export class SampleDropdown extends React.Component {
render() {
return (
<Select
className="basic-single"
classNamePrefix="select"
defaultValue={colourOptions[4]}
isSearchable
name="color"
options={colourOptions}
components={{ Option}}
hideSelectedOptions={false}
isMulti
/>
);
}
}
here is package.json ...
it has following packages
"bootstrap(^3.4.1), es6-promise-promise(^1.0.0), react(^16.8.6), react-bootstrap(^0.31.5), react-dom(^16.8.6), react-router-bootstrap(^0.25.0), react-router-dom(^5.0.0), react-scripts(3.0.0), react-select(^2.4.3), rimraf(^2.6.3), whatwg-fetch(^3.0.0"
{
"name": "reports_react",
"version": "0.1.0",
"private": true,
"dependencies": {
"bootstrap": "^3.4.1",
"es6-promise-promise": "^1.0.0",
"react": "^16.8.6",
"react-bootstrap": "^0.31.5",
"react-dom": "^16.8.6",
"react-router-bootstrap": "^0.25.0",
"react-router-dom": "^5.0.0",
"react-scripts": "3.0.0",
"react-select": "^2.4.3",
"rimraf": "^2.6.3",
"whatwg-fetch": "^3.0.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
When the React app is being build (dev or prod), spread operations are being transformed into Object.assign assignments.
A solution would be to use the babel-polyfill package and import right at the top of your entry point (index.js by default) to ensure correct functionality.
Another solution is to eject your react app using yarn eject, which will allow you to configure the build procedure of your app. You might have to delete the node_modules folder and reinstall your packages.
After ejecting you have to install the #babel/plugin-transform-object-assign package using yarn add #babel/plugin-transform-object-assign --dev and add the following to your package.json under the attribute babel:
{
...
"babel": {
"presets": ["react-app"],
"plugins": ["#babel/plugin-transform-object-assign"]
}
...
}
or the following to any babel configuration file:
{
"presets": ["react-app"],
"plugins": ["#babel/plugin-transform-object-assign"]
}
This will transform all Object.assign so they can be used inside unsupported environments (like IE11).
Ejecting is necessary for this method as facebook has the configurations for their create-react-app built-in to provide functioning defaults.

Error: Native Modules for sensors not available. Did react-native link run successfully?

I am new on React Native, could you helpe me? I have just installed the react-native-sensors(Yarn add --save react-native-sensors), then I imported on my project(import { Accelerometer } from "react-native-sensors";) but I receive this message "Native Modules for sensors not available. Did react-native link run successfully?"
I runned the command "react-native link react-native-sensors", but the error
still persists =(
I am using the "react-native-sensors": "^5.1.5".
and this is my package.json
{
"name": "tcc_mobile",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"lodash": "^4.17.11",
"react": "16.6.1",
"react-native": "0.57.7",
"react-native-gesture-handler": "^1.0.10",
"react-native-sensors": "^5.1.5",
"react-navigation": "^3.0.8",
"rxjs": "^6.3.3"
},
"devDependencies": {
"babel-jest": "23.6.0",
"jest": "23.6.0",
"metro-react-native-babel-preset": "0.48.5",
"react-test-renderer": "16.6.1"
},
"jest": {
"preset": "react-native"
}
}
Thanks ! =)
$ npm install react-native-sensors --save or Yarn add
$ react-native link react-native-sensors
Are you testing on iOS? If you are testing on iOS, you need to add this.
Option: With CocoaPods (iOS only)
Add the following to your Podfile and run $ pod install:
pod 'RNSensors', :path => '../node_modules/react-native-sensors'
Check your AVD for sensor capabilities and try to work with real devices. It woks fine for me with the given dependency version:-
"react-native-sensors": "^5.1.8". Here is a little code snippet:-
import {
accelerometer,
gyroscope,
setUpdateIntervalForType,
SensorTypes
} from "react-native-sensors";
accelerometer.subscribe(({ x, y, z, timestamp }) => {
console.log(X: ${ x }, Y:${y}, Z:${z}, timestamp: ${timestamp} )