I am in my initial stages of learning react and have a limited understanding of npm manager and importing libraries into project.
For my current project, I had installed react-native using
npm install react-native
This also reflects in my package.json and node_modules folder
"react-native": "^0.61.5"
Now, when I try to import react-native as follows into AppCarousel.js
import React from 'react';
import {Dimensions} from 'react-native';
and then build the application , i get the following error message
.\src\Components\AppCarousel.js
Cannot find module: 'react-native'. Make sure this package is installed.
You can install this package by running: npm install react-native.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react#1.0.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react#1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\{USER}\AppData\Roaming\npm-cache\_logs\2020-01-09T13_08_54_364Z-debug.log
The terminal process terminated with exit code: 1
I tried referring to the the following questions i) link1 ii)link2
I cannot make out if this is a bug in npm or if there is a lack of understanding for installing packages on my side. Any help will be appreciated, thanks.
Terminal to kill the process:
ps -ax | grep npm
Then try to navigate to your directory in your terminal and try to do write this:
npm I react
or again:
npm i react-native
Simple explanation to get in use with TypeScript and React:
https://facebook.github.io/react-native/docs/typescript
Related
I created a React Native project with Expo using expo init MapTry. I am currently trying to install MapBox library into it. For some reason I get an error at the first step after trying to install it. I followed this guide of installation: https://github.com/rnmapbox/maps#Installation but for some reason I am getting an error message when I try to run npm install rnmapbox/maps#main --save from the terminal. The error says the following:
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm ERR! code ENOENT
npm ERR! syscall spawn git
npm ERR! path git
npm ERR! errno -4058
npm ERR! enoent An unknown git error occurred
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
I also tried to search for it in the official NPM site and found this one: https://www.npmjs.com/package/#rnmapbox/maps . After running the following code: npm i #rnmapbox/maps which was written there, I get the same error message as written above. What should I do? How can I use MapBox library in React Native?
try to run this command in your terminal
with NPM
npm install #rnmapbox/maps --save
with YARN
yarn add #rnmapbox/maps
I'm following the setup instructions from the React Native Documentation page, on my M1 Macbook Pro. I have previously worked on React projects and was able to create and run React Native Expo projects previously on the same machine.
I followed the instructions to the letter, but when I arrived at the 'Create A New Application" section, using the npx react-native init AwesomeProject command, the new project creation failed. Here are the error message outputted on the Terminal:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: undefined#undefined
npm ERR! Found: react-native#0.66.4
npm ERR! node_modules/react-native
npm ERR! peer react-native#"*" from #react-native-community/cli#6.3.1
npm ERR! node_modules/#react-native-community/cli
npm ERR! #react-native-community/cli#"^6.0.0" from react-native#0.66.4
npm ERR! react-native#"0.69.2" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! react-native#"0.69.2" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: react#18.0.0
npm ERR! node_modules/react
npm ERR! peer react#"18.0.0" from react-native#0.69.2
npm ERR! node_modules/react-native
npm ERR! react-native#"0.69.2" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
I tried to uninstall react-native and install it back but couldn't find a proper instruction on the net to do that. How can I just scrape the previously installed react-native (judging from the error message, i got RN#0.66.4, when I want to use the latest RN) and install a fresh, latest react native?
if you are on Mac and your node version is 18.. which Is latest but not greatest.. you need to download 16.. the stable one.
Step-1
brew uninstall node;
# or `brew uninstall --force node` which removes all versions
brew cleanup;
rm -f /usr/local/bin/npm /usr/local/lib/dtrace/node.d;
rm -rf ~/.npm;
Step 2 - and install it from node site by downloading the binary
Step 3 - just check the node version again if you have 16..
then you can try creating the react native project once again.
Please let us know if it worked for you. Wish you luck!!
In addition to what the answer suggests, you can do brew install node#16 to install this particular version instead of manually downloading the binary.
If installing node version 16 doesn't work for you ensure you update npm by running sudo npm update -g.
I am new to backend and I am having issues creating react app.
I have started fresh multiple times and create a brand new terminal which I cd in a folder named "client".
As I type npx create-react-app./ I get this error:
ritamiranda#Ritas-MacBook-Air new project % cd client
ritamiranda#Ritas-MacBook-Air client % npx create-react-app./
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /Users/xxx/Desktop/new project/client/create-react-app./package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/Users/ritamiranda/Desktop/new project/client/create-react-app./package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/xxx/.npm/_logs/2022-07-04T18_25_05_983Z-debug-0.log
ritamiranda#Ritas-MacBook-Air client % cd [client]
zsh: no matches found: [client]
ritamiranda#Ritas-MacBook-Air client % npm create react app
npm ERR! could not determine executable to run
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/ritamiranda/.npm/_logs/2022-07-04T18_26_41_818Z-debug-0.log
ritamiranda#Ritas-MacBook-Air client %
please help, thank you!
Creating a React Project
I believe you're actually missing naming your app.
To create a project, navigate to the folder where you want to store the project and from the terminal run:
npx create-react-app my-app
Instead of my-app make sure to choose whatever name you want to call your project.
You can create a project with Vite. It is faster than the comparatively traditional way. You can run the below code in your terminal.
npm create vite#latest myapp
I'm new to React and I want to create a new component by a command.
The command which I want to create will be the same output of the command in Angular 2: "ng generate component Test".
I have search on the internet and there is a reference: https://www.npmjs.com/package/create-reactjs-component.
However, it doesn't work for me. The terminal shows errors:
PS C:\Users\anhtranv1\Desktop\react-app> npm install -g create-reactjs-component Test
npm ERR! code E404
npm ERR! 404 Not Found: Test#latest
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\anhtranv1\AppData\Roaming\npm-cache\_logs\2018-10-
29T10_39_16_863Z-debug.log
Is there anyone can give me a command to create a component in react?
Thank you in advanced.
With npm install -g create-reactjs-component you install the npm package globally.
After you installed the package globally with the above command you can create a component with create-reactjs-component YourComponentName.
Please read the documentation of the package, it's all described there.
You might want to check out generate-react-cli. Really straightforward and easy to use.
install: npm install -g generate-react-cli
run: generate-react component Box
That's it
repo: https://github.com/arminbro/generate-react-cli
What are you telling him here :
npm install -g create-reactjs-component Test
Is to install Globally create-reactjs-component AND Test, however there is no Test defined in npm repository,
Install your CLI tool dep
Create your component
I want to be able to test my app on Expo (an IPhone app used to test React Native code after you hit save) and I just can't seem to get past this error I'm getting Terminal. I've ran my app using Expo before with no problems but now after trying to include a Navigator in my app, I get an error.
First I did this:
$ npm i -g create-react-native-app
$ create-react-native-app my-project
$ cd my-project`
Then I wanted to include a Navigator in my app so I went ahead and did this:
npm install --save react-navigation
After that, in order to get Expo running I did:
npm start
When I do npm start, I get this error in Terminal:
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! Mestro#0.1.0 start: `react-native-scripts start`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the Mestro#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
my guess would be that you are using npm5, I would recommend using npm4, npm5 is currently (as of june 17, 2017) very buggy. see this recommendation in the README.