Struggling to make redux function properly in react-native

Currently, I am attempting to work through a basic redux example:

This particular example involves storing a number in a reducer that simply increments it. The code solely imports redux without any additional dependencies such as redux-persist or react-redux.

However, the main issue arises when trying to install all the required dependencies. Previously, running react-native apps was smooth sailing until introducing redux. Following a react-native init and executing run-ios, an error pops up indicating that redux cannot be found. Here are the steps I have attempted:

$ npm install --save redux

Unfortunately, this command caused complications as it resulted in:

added 5 packages, removed 617 packages, and updated 17 packages in 8.839s

Subsequently, run-ios or run-android ceased working and displayed:

Command run-ios unrecognized. Make sure you have executed npm install and that you are inside a react-native project.

Even after multiple attempts of npm install or npm install update, no progress was made and the same error persisted.

In light of this, I decided to start afresh by creating a new project and inserting the code into index.ios.js using yarn instead (despite being unfamiliar with npm or yarn).

$ yarn add redux 

Nevertheless, upon running run-ios, an error box appeared:

Can't find variable: React

The source of this error traced back to:

<Text style={{fontSize: 100}}> 

thus pointing to a probable issue within react-native (specifically ReactCompositeComponent.js). As a result:

$ yarn add react 

Despite this, another red box error resurfaced stating it cannot resolve react/lib/ReactDebugCurrentFrame along with a list of directories where it could not locate it.

It seems odd that npm install --save redux would cause deletion of crucial node_module files. Has anyone successfully tackled this issue?

Answer №1

Two challenges arose for me. Initially, when running npm install --save redux (or react-redux), many node_modules were inexplicably deleted. Though the cause remained a mystery, reinstalling both node and watchman (via brew uninstall --force followed by install) resolved the issue. Secondly, I found it necessary to include import React, { Component } from 'react'; at the beginning of the file.

Answer №2

To include packages using yarn, make sure you have yarn installed globally. The command react-native init project-name automatically uses yarn. If you try to install packages with npm install, it will remove the node_modules directory because the initial setup of the react native app was done with yarn.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Implementing a fetch request in React-Native and handling the returned

Currently, I am facing an issue in the renderImage() function where I need to return a piece of code, but it is not working as expected. Despite trying out different solutions, I am unsure of what else to do at this point. The error that I am encountering ...

Template7 produces a bizarre outcome referred to as "each this" whenever JSON is utilized

Currently, I am experimenting with dynamically loading content on Framework7/Template7 pages. Everything works perfectly fine when using static "context" in JSON format. However, when attempting to test it with real-world data from an API, I encounter a st ...

Unsure about how to use React's onbeforeunload function

When the state variable someVar is set to true, a message will be displayed to the user upon leaving the page (e.g., refreshing, going back, or clicking the close button on the window/tab). If the user selects Cancel on the message, they will stay on the p ...

Numerous SVGs sharing identical IDs

Is it possible to include multiple SVGs on an HTML page and utilize the same IDs in each of them? <div> <svg height="0" width="0"> <clipPath id="svgPath"> ........ </svg> <svg height="0" width="0"> < ...

Steps for adding a PHP dropdown menu to an HTML/Javascript webpage

Hey there, this is only my second post and I have to admit that I am a newbie in the world of web development. I'm spending countless hours scouring different websites for guidance, and I'm finally starting to grasp some concepts (at least for no ...

Encountering an error while attempting to install angular-ide, receiving a "operation not permitted" error message. Tried running

<pre>fs.js:114 throw err; ^ Error: EPERM - unable to perform operation, chmod '/usr/lib/node_modules/angular-ide/bin/ng' at Object.chmodSync (fs.js:1027:3) at Object.<anonymous> (/usr/lib/node_modules/angular- ...

Dissecting Distinct and Alphabetized Attributes in JSON/JavaScript

Below is a code snippet that retrieves and organizes a list of values from JSON data in alphanumeric order based on a specific key-value pair: var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 &a ...

Tips on how to dynamically update information with Angular

Looking to dynamically update data when a user selects an option from a dropdown menu using the Angular framework This is what I currently have: <div> <button type="button"> {{tests[0].test}} </button> <ul c ...

"Utilize parameter passing with mapGetters in the Vuex state management system

Hello there! I'm currently working on a Vue.js project and using modules. I am trying to get filtered data from a getter, but I'm unsure how to provide parameters. Specifically, I need to pass a 'name' parameter to the Getter. How can ...

Ways to split images and text in list items using CSS

Can the text be formatted in a specific location on the page, separate from the image and heading? This is the HTML code I am currently using: <div class="tab-pane container fade" id="environmental"> <div class="row"> <div class="c ...

Learn how to display two different videos in a single HTML5 video player

Seeking a solution to play two different videos in one video element, I have found that only the first source plays. Is jQuery the answer for this problem? HTML Code: <video autoplay loop id="bbgVid"> <source src="style/mpVideos/mpv1.mp4" type ...

What is the reason behind Material UI Alert Dialog having a black background?

My goal is to display an alert dialog whenever a user taps on a button within a material ui DataGrid component. However, I am currently facing an issue where the background of the alert dialog appears black instead of transparent. Here is what the button ...

Can you explain the process that takes place when require("http").Server() is called with an Express application passed in as a parameter?

As I was exploring the Socket.io Chat Demo found at this link: http://socket.io/get-started/chat/, I came across their require statements which left me feeling confused. var app = require('express')(); var http = require('http').Server ...

What are the essential Angular 2 observables for me to utilize?

I have created a form input for conducting searches. Upon user input into the search bar, I want to trigger calls to two separate APIs simultaneously. Here is my current attempt: myInput: new FormControl(); listOne: Observable<string[]>; listTwo: Ob ...

Requesting data asynchronously using AJAX and displaying the filtered results on a webpage using JSON

When I send a request to my node.js server for a .json file containing person information (first name, last name), I want the data to be filtered based on user input. For example: When I request the .json file from the server, it gives me a list of people ...

RTK Query is unable to assign a tag ID

I'm currently setting up RTK Query and facing some challenges with defining a tag-id. Despite my efforts, I can't seem to get the "Timeseries" tag to function properly with an id. Below is the API configuration: export type GetTimeseriesProps = ...

Error message encountered: "myData undefined while executing server in Node.js"

const express = require('express'); const app = express(); app.post('/', (req, res) => { let newData = new contact(req.body); newData.save() .then(() => { res.send("Data has been successfully saved to ...

Invoking instance methods of Ajax XMLHttpRequest

function fetchJSONData(url, callback){ var request = new XMLHttpRequest(); request.open('GET', url, true); request.onprogress = function(event){ console.log(event.loaded, event.total); }; request.addEventListener(&apos ...

Using ui-tabs with Ng-repeat to create both dynamic and static tabs

I'm currently working on creating a date tabs feature where users can click to add more tabs. Below is a snippet of the code I'm using: `<uib-tabset justified="true" class="ui-tab"> <uib-tab ng-repeat="date in dates track by $index" hea ...

What port and protocol does npm utilize for communication?

While executing the command npm install Which protocol and port is utilized to retrieve the node_modules folder files? I have not been able to find this information through my own research on various platforms. ...