How to run React project - reactjs

I have a project in React. It is cloned from Git-lab. I consist of two separate aplications: backend and frontend. Question is simple. How to run it? It should contain Laravel implementation but I dont see anythind inside. Is there any npm commant I need to run? I think npm create-react-app is not the right command of exisiting aplication. I am sorry for this trivial question. This is my first contact with React.

If you see package-lock.json file, try npm install and npm start. If there is yarn.lock file, try yarn install and yarn start. You need to run "install" command only once (and after change of package.json).

I open Git Bash command window and when it is at the correct directory type NPM START. Being that you have both back and front end you would open two BASH windows and do this for each (backend first).

it simple,first of all you open terminal and type a npm run start command.application running started. then all done you will display the url then you entered in your browser it work.

Related

Simple NPM Question Re-updating local react project after other dev added new package

I just started working with vscode and npm/git. Someone on my team added a package and I did a pull to get his latest changes which put that package in my package.json file. When I ran the project I got errors for a module not being found. Obviously I need to install that package locally. Do I simply use npm install w/no arguments to get it? Or do I install it manually myself with npm install and version info? I ask because I don't know if npm install w/no args will create a new package.json or cause any issues.
What is the correct way to get a new package installed that someone added in the repo?
npm install can be run as many times as you like, and is what you should be doing here :)
npm install's purpose is to get your node_modules folder up-to-date with whatever is written in package.json
So, if your colleague has changed package.json (by installing something new and pushing the change to git), you can just run the command again to get up-to-date.
Provided you haven't directly fiddled with any files in node_modules (this folder should be left alone), it is always safe to run npm install as many times as you like, even if nothing has changed.

npm ERR! Response timeout while trying to fetch https://registry.npmjs.org/react-is (over 30000ms)

When I want to create a react app I'm encountering the following error:
npm ERR! Response timeout while trying to fetch https://registry.npmjs.org/react-is (over 30000ms)
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\info\AppData\Roaming\npm-cache\_logs\2020-04-23T02_54_45_865Z-debug.log
Aborting installation.
npm install --save --save-exact --loglevel error react react-dom react-scripts cra-template has failed.
Deleting generated file... package.json
Deleting app2/ from C:\Users\info
Done.
Sounds like you have a slow connection. Try increasing the timeout from 30s to 60s by adding this to your .npmrc file:
timeout=60000
You could also try adding
prefer-offline=true
if you are trying to save bandwidth or have a slow connection
Note: if you don't have an .npmrc file setup yet, you can create one here
for Windows: C:\Users\{username}\.npmrc
for Mac/Linux ~/.npmrc
Or you can create one in the same directory as your project's package.json file.
I had a slow connection and I updated the timeout value to .npmrc using:
npm set timeout=100000
And to check if the value is updated (Mac): vi ~/.npmrc
Users are extremely likely to face this issue if they are on a slow internet connection. To counter this, you need to increase the timeout in the npm's config file. And here's how to do it:
Find the .npmrc file (located in the nodejs installation folder; in my case, it's in F:\Installations\nodejs\node_modules\npm folder. But for you, it might be in C:\program files folder).
Open the .npmrc file and append this line: timeout=240000 (usually it is 60 seconds I suppose, but since my connection was way slower therefore, I had to increase it to 240 seconds or 4 minutes, you can keep it 120000 for 120seconds)
Save the file
Since create-react-app fails midway, it can easily break npm's package.json file thus leading to this sort of issue:
Unexpected end of JSON input while parsing near
Therefore, before running the npx create-react-app, run the following command: npm cache clean --force as it cleans the cache and (i think) repairs the package.json file.
I was facing the same issue. I Solved it like this:
create a new file with no name just an extinction of .npmrc
open this file in any editor and type timeout = 90000
save the file and in you terminal type
npm cache clean --force
npm install create-react-app
npx create-react-app ./
Note: this error occurs because of slow internet speed
This error occurs due to slow internet connection. Try installing when you get a better speed. If better speed doesn't solve your problem try this.
npm cache verify
npm cache clean --force
I enabled IIS and the issue was solved for me:
do to Control Panel -> Programs -> Programs and Features
click on Turn Windows features on and off
make sure the Internet Information Services is checked
click OK and wait for some minutes
I was facing the same issue when create a react-app using npx create-react app . And i fixed my problem by running the following command.
npm cache clean --force
I hope you find this helpful
I fixed the problem by setting timeout in user local .npmrc file to
timeout=600000
90000 is not enough for downloading many packages for projects with lot dependencies in package.json
In case you are still running into this issue below with the error:
Invalid response body while trying to fetch
https://registry.npmjs.org/eslint-config-react-app: Socket timeout
Run this script: npm install react --registry=https://registry.npmjs.org
and then npx create-react-app mypp
for your react app installation. Happy coding
I fixed the problem by running:
npm config set registry "http://registry.npmjs.org" --global
It appears the problem is related to the following post:
npm install gets stuck at fetchMetadata
And #CptUnlucky's solution worked for me on macOS Catalina 10.15.7, node v16.0.0, npm v7.12.2, nvm v0.38.0
I was facing the same issue and I solved it by enabling the Internet Information service (IIS) feature of the window.
Enabling the IIS
Steps:
Windown + r
Type appwiz.cpl and click OK
click on Turn window features on or off (on the Left top side)
wait some seconds and check the Internet information service option
Now wait until window apply changes.
create project again.
I have faced the same issue. I tried all solutions over StackOverflow or Github discussions but nothing worked.
I changed the .npmrc file under the Users folder in C in Windows and changed the timeout from 30000 to 90000. See if 60000 works!
In my case it was the issue related to npm verison 6.14*
Downgrading to npm verison 6.13.7 solved for me
npm i -g npm#6.13.7
It's also an newly opened issue
you can check more details about it at
https://github.com/npm/cli/issues/1185
You just need to run npm i npm#6.13.7 or npm I -g npm#6.13.7 if you wanna this to be global version.
After that, just to make sure, run " npm -version " to see what version you are using.
Downgrading to npm version 6.13.7 worked for me.
Try this:
npm cache clean --force
npm config rm proxy
npm config rm https-proxy
And remove your node_modules within your user.
In Windows, it is
C:\Users\${select_your_user}\AppData\Roaming\npm\node_modules
I was facing the same issue when running npm install on Docker.
I had to pass the HTTP and HTTPS proxy values to the image while building it.
docker build --build-arg HTTP_PROXY=http://<your_company_proxy> --build-arg HTTPS_PROXY=http://<your_company_proxy>
It worked fine after I passed these parameters.
In my case it was the issue related to npm verison 6.14*
Downgrading to npm verison 6.13.7 solved for me
npm i -g npm#6.13.7
It's also an newly opened issue you can check more details about it at https://github.com/npm/cli/issues/1185
it is works for me
Editing the .npmrc file to 80000 works. If not, globally uninstall create-react-app:
"npm uninstall -g create-react-app" then run "npx create-react-app ./"
I recently have the same issue and following steps would help you.
npm config set registry "http://registry.npmjs.org" --global (sets registry) (Try Again)
Go to you user folder find .npmrc file there and remove content of it.
run npm cache clean --force
still errors - Remove the content of npm base folder usually inside User/AppData/roaming/npm/...
I tried everything including factory resetting my Mac. Then after reinstalling everything and still having the same issue, I typed into the terminal and ran:
npm set timeout=100000
then sat my computer next to my router and ran npx create-react-app again and it worked!
Sometimes it won't work if you use only letters in your app name e.g first I have used "myapp" and that was not working though I have done all the other stuffs correctly like set timeout = 240000 in .npmrc file and run the following commands
npm cache clean --force
npm install create-react-app
npx create-react-app myapp
but that not working for me then I have just changed my project name from myapp -> my-app and it worked perfectly. So, If you are facing the same issue try them out. Hopefully, it saves your time.
I tried many things for 3 days, then i figure out that new versions of nodejs doesn't work so fine for some computers, i downgrade to 16.0.0 and then worked
Regarding npx ...
If you have create-react-app (CRA) globally installed;
it is recommend you uninstall CRA
to ensure that npx always uses the latest version.
When using npx, the global installation isn't used.
But it may interfere (addressed below).
Don't run your React app from your desktop.
Some operating systems may throw an error.
Windows OS users ...
As administrator (for steps #1 & #2), inside your command-line ...
1) uninstall your global version of CRA.
npm uninstall -g create-react-app Mac prefix: sudo
2) Then ...
Run: npx create-react-app my-app Mac prefix: sudo
Above: This will create the latest version of
a React app named: my-app.
This app will be created wherever your command-line is pointing.
3) Open Google Chrome.
4) cd my-app (point your command-line to your project folder).
5) inside your command-line ... Run: npm start

Git repository initialized, how to run npm in terminal, (turn it on or off?)

Okay, the title might be confusing but I think my problem is pretty easy to explain with just the terminal code. My questions are below the code wall. emphasized text
[fsevents] Success: "/Users/Name/my-app/node_modules/fsevents/lib/binding/Release/node-v64-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile
+ react-dom#16.6.3
+ react-scripts#2.1.1
+ react#16.6.3
added 1768 packages from 678 contributors and audited 35639 packages in 81.268s
found 0 vulnerabilities
Initialized a git repository.
Success! Created my-app at /Users/macbookpro/my-app
Inside that directory, you can run several commands:
npm start
Starts the development server.
npm run build
Bundles the app into static files for production.
npm test
Starts the test runner.
npm run eject
Removes this tool and copies build dependencies, configuration files
and scripts into the app directory. If you do this, you can’t go back!
We suggest that you begin by typing:
cd my-app
npm start
So, how do I safely terminate this, and then turn it back on? Or does it need to stay running, and if it's terminated, need to be reinstalled with the "npx create-react app" command?
I guess I'm just wondering how to access "that directory."
I understand it's probably a super basic question, but it would help me get a grip on managing my react app.
Thank you!!
terminate and turn it back on
You can terminate the project with CTRL + C or CTRL + Z.And after the termination, you can feel free to restart it.
Assuming your project runs at port 3000,if you terminal your project, you won't be able to get your project in the browser.
If you want to get your project like in http://localhost:3000, you need to make the project stay running.
npx command
There is no need to "npx create-react app" again. "npx create-react-app my-app" command will install create-react-app command globally but momentarily, it was only needed when initial project.
access "that directory"
I think the message you post above has told you.
We suggest that you begin by typing:
cd my-app
npm start
If you choose npm start the watcher will be continuosly running for development process.. you can stop it pressing CTRL + C twice on terminal.
npm run build runs once and stops alone generating files for production (compiled, minified).
Actually after installation completed, you don't need to terminate it.
To enter the project directory, simply type cd my-app
Then to start the development server type npm start
it will take few seconds to bring you to the browser (my-app project opened).
You may like to see the address bar of the browser to know the running port of development server.
When you need to stop the server just press ctrl + c
If you forget the project directory's location in mac, you can find by mdfind kind:folder "my-app"
Optional: If you use Visual Studio Code then you can type code . being inside the project directory to open up the full project directory with VS Code.

create-react-app hangs when initializing an app

It's my first time trying to use it, but after executing:
create-react-app myproject
I get:
Creating a new React app in C:\project
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
[ ................] \ fetchMetadata: sill resolveWithNewModule js-tokens#4.0.0
And it just hangs there forever.
I'm using npm 5.6.0 and create-react-app 2.0.3 on Windows 8.
I had this problem, mine got stuck at
Creating a new React app in C:\project
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
[ ................] \ fetchMetadata: sill resolveWithNewModule react-is#4.0.0
The solution for me was to ensure npm is up to date by running:
npm install npm#latest -g
After this, create-react-app worked correctly.
If you get stuck while running create-react-app, just Ctrl + C to end the process in the terminal or CMD.
Then end task "node.exe" from task manager (if you use windows).
Then run in your terminal:
npm install npm#latest -g
npm install create-react-app -g
npx create-react-app (your-project-name)
cd (your-project-name)
npm start (inside your code editor, e.g. VSCode)
Note: beware of npm vs npx in the commands used above
What I just did is press ctrl + C. My intention is to abort the process, but turns out the process is continue. Still not know any further logical explanation of the 'solution' that I just did, though.
Re-install Node js 32 bit.
My problem got fixed and same issue was there. Solution is to uninstall Node js and reinstall 32 bit Node js.....Enjoy Thanks
I was having the same problem, what i did is to run the command in nodejs command prompt instead of command prompt. it worked for me
Since you have npm 5.6.0, let try using npx
Open cmd:
Locate to you C:\project
C:
cd C:\project
Run npx and start the sample project with npm:
npx create-react-app myproject
cd myproject
npm start
npx come out since npm 5.2, and just read the document from create-react-app here
Open a new terminal/CMD, type resmon and hit enter. Go to overview tab and search for
cmd.exe (for windows users), straight to that, search for suspended. Yes this is the culprit. Right click on that suspended, and click 'resume process' and hit enter.
Click continue if any pop-up occurs :).
That's it you are done. you will see that your installation will continue :).
Repeat the same process if CMD hangs.
adding nodejs path in User Variable worked for me.
Try this; it worked for me:
npm install -g create-react-app
then run your command.

"npm start" command suddenly stopped working with "create-react-app" project folders with both old and newly created projects

I've been using create-react-app to make some projects in react and also for practicing, and usually the way to run the project is to use the command npm start from the root directory of that project in the terminal. This has since stopped working for both my old projects which I haven't touched or completely new ones, and followed the exact instructions given by the error already to no effect.
An image of the error, the very top of the terminal is immediately after the npm start command:
I have been googling this over the past two days and I simply can't figure it out. I'm hoping someone with better knowledge would know the root of why npm start has stopped working. Please keep in mind that I already tried the suggestions provided by the error in the terminal.
What's really mind boggling is I haven't changed pcs or done any editing in the old projects such as the one in the picture above, re-installed a bunch of stuff I thought might have been causing issues like npm or babel but they simply don't launch anymore.
Also almost forgot the error log, which has been even more confusing to figure out or google:
You have problem with your dependencies. Please run
npm i
inside project directory.
As your console shows, you can try
remove your node_modules directory
delete file package-lock
I suggest clean npm cache (npm cache clean -f)
and reinstall node_modules using
npm i
There are many reasons to cause this problem.Some suggestions here:
1.uninstall babel-loader and create-react-app globally
npm uninstall -g babel-loader
npm install -g create-react-app
2.remove the error package
rm -rf ~/node_modules/babel-loader
3.stop all the command then clean up the cache of npm

Resources