Why Gatsby Browser Error occur when run create react app? - create-react-app

I want use gatsby-image in a create react application and when i install gatsby in react and after execute i got this error
Failed to compile.
./node_modules/gatsby/cache-dir/gatsby-browser-entry.js
SyntaxError:
/node_modules/gatsby/cache-dir/gatsby-browser-entry.js: Unexpected
token (25:4)
return (
<React.Fragment>
^
{finalData && render(finalData)}
{!finalData && <div>Loading (StaticQuery)</div>}
</React.Fragment>

Related

React Native Jest doesnt exit, and show the actual library as the cause of the problem

Im implementing tests framework (jest) in react native with testing-library/react-native, on an existing project.
When I run their example (intro) the app give the infamous error:
Jest did not exit one second after the test run has completed.
when I try to check it with the flag --detectOpenHandles, it shows that the library itself is the problem.
I have no config file for jest.
RN - 66.4
jest - 28.1.0
babel-jest - 26.6.3
jest-circus - 26.6.3
eslint-plugin-jest - 26.1.1
My problem was solved by this code:
beforeAll(done => {
done()
})
afterAll(done => {
// Closing the DB connection allows Jest to exit successfully.
mongoose.connection.close()
done()
})

can't run react native with npm start

hi i'm very beginner in react native i create react native app using expo init
and after that i go an on this folder and run npm start its give me an error
mohit#mohit-PC:~/Desktop/this is not for you/rn$ cd fp/
mohit#mohit-PC:~/Desktop/this is not for you/rn/fp$ npm start
fp#1.0.0 start
expo start
Starting project at /home/mohit/Desktop/this is not for you/rn/fp
RangeError [ERR_SOCKET_BAD_PORT]: options.port should be >= 0 and < 65536. Received 65536.
at new NodeError (node:internal/errors:371:5)
at validatePort (node:internal/validators:216:11)
at Server.listen (node:net:1461:5)
at /usr/local/lib/node_modules/expo-cli/node_modules/freeport-async/index.js:8:12
at new Promise ()
at testPortAsync (/usr/local/lib/node_modules/expo-cli/node_modules/freeport-async/index.js:6:10)
at availableAsync (/usr/local/lib/node_modules/expo-cli/node_modules/freeport-async/index.js:24:17)
at /usr/local/lib/node_modules/expo-cli/node_modules/freeport-async/index.js:37:23
at new Promise ()
at freePortRangeAsync (/usr/local/lib/node_modules/expo-cli/node_modules/freeport-async/index.js:33:10)

Check if device is jailbroken/rooted using Jail Monkey in React Native fails module is 'undefined'

In React Native I found two plugins to check if a device (iOS/Android) is jailbroken/rooted:
Jail Monkey
react-native-is-device-rooted
I have firstly tried the npm package react-native-is-device-rooted but it doesn't work and it seems to be outdated. So I tried Jail Monkey, but I get this following error:
The code is:
import JailMonkey from 'jail-monkey'
export default class Welcome extends Component {
render() {
return (
...
<View style={styles.lowerView}>
<CustomButton text={"Jail Monkey"} onPress={() => this.printJailMonkey()}/>
</View>
...
);
}
printJailMonkey = () => {
console.log("Jail Monkey library content: " + JailMonkey.isJailBroken())
}
}
I have checked carefully the manual link of the package (using Xcode, pod install, and so on...). Nothing worked, does someone can help me?
JailMonkey uses Native Modules and thus cannot run in an Expo managed app. You need to eject it to ExpoKit for JailMonkey to work.
Solved but doing manually the linking.
Try following steps for manual linking.
Navigate to root folder in terminal enter commands:
react-native link
cd ios
pod update

navigator.geolocation.getCurrentPosition is not working in React Native Version(0.60) and above, How to fetch location?

Trying to fetch current Location using geoLocation, it is not working in React Native version(0.60) and above, But it is working in below versions
I realised, GeoLocation folder is not there in nodeModules/React-Native/Libraries,
did they remove it from ReactNative(0.60)?
navigator.geolocation.getCurrentPosition((position) => {
console.log(position)
},
(error) => alert(JSON.stringify(error)),)
Getting this error:
Type Error: Undefined is not an object(evaluating
'navigator.geolocation.getCurrentPosition
It seems geolocation has been removed from react native .60 version.
Try this:
npm install #react-native-community/geolocation --save
react-native link #react-native-community/geolocation
You can check this related SO post for more details.
npm install #react-native-community/geolocation --save
react-native link #react-native-community/geolocation
then:
import Geolocation form '#react-native-community/geolocation';
Geolocation.etCurrentPosition((position) => {
console.log(position)
},
(error) => alert(JSON.stringify(error))

React Native MQTT Module `url` does not exist in the Haste module map

I want to explore this project https://github.com/mqttjs/MQTT.js within the React Native environment. So I did this:
react-native init myproject
npm install --save mqtt
Then I pasted this sample code from the mqttjs into my App.js a bit after the "Welcome to React Native" component.
var mqtt = require('mqtt')
var client = mqtt.connect('mqtt://test.mosquitto.org')
client.on('connect', function () {
client.subscribe('presence', function (err) {
if (!err) {
client.publish('presence', 'Hello mqtt')
}
})
})
client.on('message', function (topic, message) {
// message is Buffer
console.log(message.toString())
client.end()
})
But when I run react-native run-android, I get a compilation error with a message like
Module url does not exist in the Haste module map
I tried replacing mqtt://test.mosquitto.org with a url to my own mosquitto broker with some of these values: mqtt://192.168.0.20, tcp://192.168.0.20, 192.168.0.20. But all these still generated the same error.
What am I doing wrong?
You can solve this by explicitly installing the url module:
npm install url