Deploying React App from Codesandbox to Github Pages - reactjs

I followed this youtube tutorial to deploy my react app to github pages. I made my react app in codesandbox and exported my sandbox to my github. I downloaded node.js, npm, and git.
My folder structure:
Users > test > package-lock.json + andair-master > (inside andair-master) node_modules + build > (inside build) public + src + package.json
I downloaded my github project "andair-master" and copied and pasted its contents into an empty folder "test".
I opened Git Bash and changed directories until I was in "andair-master". I did "git init" then "git remote add origin https://github.com/develijahlee/andair.git" then I tried "npm run deploy". I realized I was missing a "build" folder so I made one within the "andair-master" folder. Then I put my "src" and "public" folders inside the "build" folder and tried running "npm run deploy". Still not working. I notice that my github is missing a gh-pages branch. I am not sure how to make a gh-pages branch or why "npm run deploy" is not working. If anyone could tell me if I'm missing a step, that would be greatly apprecitated. Thank you.

There are a few missing dependencies in your create-react-app project. This probably happened because you tried to export the project from codesandbox (I'm not sure though)
You have to fix those first.
Dependency 1 (react-scripts):
npm install react-scripts --save-dev
Dependency 2 (node-sass because you are using scss in your project)
npm install node-sass --save
Dependency 3 (gh-pages)
npm install gh-pages --save-dev
After the above steps are completed, verify your package.json to match below structure
{
"name": "and-air",
"version": "1.0.0",
"description": "",
"keywords": [],
"main": "src/index.js",
"homepage": "https://develijahlee.github.io/andair/",
"dependencies": {
"#fortawesome/fontawesome-svg-core": "1.2.25",
"#fortawesome/free-regular-svg-icons": "5.11.2",
"#fortawesome/react-fontawesome": "0.1.5",
"node-sass": "^4.13.0",
"react": "16.9.0",
"react-dom": "16.8.6"
},
"devDependencies": {
"gh-pages": "^2.1.1",
"react-scripts": "^3.2.0",
"typescript": "3.3.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
Now you can run the deploy script
npm run deploy
After this step, verify that a new branch created with name gh-pages
Click on the settings tab in github
Scroll down to the GitHub Pages section and switch your branch to gh-pages branch.
You should get a success message when the page is live.

Here is what deploy script in your code:
"deploy": "gh-pages -d build"
Which is means gh-pages tool use build directory to make it deploy, so you need two things in order to make it work
Create a build folder properly with the following command:
npm run build
now install gh-pages tool for your add locally:
npm i gh-pages
Now you can run deploy command, and it'll work.
I hope this can be helpful to you.

Related

Deployed several HTML sites but unable to host React on Firebase

I have successfully deployed several HTML sites on Firebase but this time trying to publish the React one written on TypeScript when I visit it says Site Not Found
I found one should use build folder when deploying to firebase to look for source, unfortunately I can't find any build but dist available, so I tried the same
Overview of my app structure
src contains assets, main.tsx etc
public (empty directory)
dist gets generated and contains index.html, assets
root contains src, public, dist, index.html, package.json etc
I hope you've realized, I am new to React and just started with a simple Hello World app (works great offline) and just trying to host same on Firebase
Following NPM Commands, I've used to build and run an app offline
npm install
npm run build
npm run dev
That's what package.json looks
{
"name": "helloworld",
"version": "0.0.1",
"private": false,
"scripts": {
"build": "tsc && vite build",
"dev": "vite",
"format": "prettier --write .",
"lint": "eslint --fix . --ext .ts,.tsx",
"lint:css": "stylelint --fix '**/*.css'",
"preview": "vite preview"
},
....
}
Link to YouTube tutorial, I always follow to host a website on Firebase

Stuck at Edit src/App.js and save to reload at heroku

I am extremely new to React, I successfully push my code in Heroku at https://react-heroku-juvie.herokuapp.com/ ,but I'm still stuck at this
Edit src/App.js and save to reload.
What I did is
npx create-react-app react-heroku
cd react-heroku
npm run build
npm i -g heroku (...login creds)
heroku create react-heroku-juvie
git remote add heroku
git add.
git commit -m "Initial Commit"
git push heroku master
I want my app to function and display. How do I do this? Here's my src code https://github.com/juvielone/pocketNote.git
I had the same problem but in fact after running your app locally you are supposed to produce a build, see https://create-react-app.dev/docs/deployment/
I don't know how to proceed with Heroku, you could begin with the command:
$ npm run build
I guess it's quite complicated with heroku, so I suggest you try with Github Pages.
Here is what I did with github pages: I began with the command:
$ npm install --save gh-pages
(in the main directory of my app).
After that in my package.json file I added 3 lines: 1 for my homepage (line 5) and 2 for the "predeploy" and "deploy" scripts in the scripts section (lines 15 and 16), as here (it's the beginning of my package.json file):
{
"name": "client",
"version": "0.1.0",
"private": true,
"homepage": "https://SebastienBosca.github.io/defi3w",
"dependencies": {
"bootstrap": "^5.1.3",
"react": "^17.0.2",
"react-bootstrap": "^2.2.3",
"react-dom": "^17.0.2",
"react-scripts": "3.2.0",
"web3": "^1.6.1"
},
"scripts": {
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
After that I ran
$ npm run deploy
(which runs npm run build and gh-pages -d build); I am asked my Username (put your email or usernam on github) and my password (here, putting your Personnal Access Token is mandatory, you password won't work).
That's all !

React: missing script: start

how to run npm start
Bhanukas-MacBook-Pro:Shopping Card Admin Panel bhanukaisuru$ npm start
npm ERR! missing script: start
npm ERR! A complete log of this run can be found in: npm ERR!
/Users/bhanukaisuru/.npm/_logs/2019-05-01T05_42_52_916Z-debug.log
package.json file
{
"name": "shopping-cart-admin-panel",
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.18.0",
"bootstrap": "^4.3.1",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-router-dom": "^5.0.0",
"react-scripts": "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": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"proxy": "http://localhost:3000"
}
I can see you do have "start" script in your package.json
"scripts": {
"start": "react-scripts start", <--- here
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
react-scripts is a set of scripts from the create-react-app starter pack.
You need to run npm start command in your terminal in order to run the app.
In common apps, the start script looks like so:
"start": "npx node index.js"
Where index.js can be also the server.js file
it is because of global installation of create-react-app or your node.js is not updated.follow the below steps
uninstall react from global
----> npm uninstall -g create-react-app
Then try to update the npm and all the packages.
----> npm install -g npm#latest
Now create your new react app
----> npx create-react-app yout-app-name
I had this same problem at an early stage. Getting the error:
npm ERR! missing script: start
For starters, make sure that you are in the "client" (cd client) or whichever name that you chose to build your creat-react-app 's client side.
It seems as if you already have your start and react-scripts, so hope this helps.
I had the same issue and spent a whole day trying to fix it, only to realize that the root folder in which I created the react app had a "&" sign in it. npm has looked up the start script on an invalid folder path by omitting the characters before and including the &. Once I moved the project to a no-nonsense folder path, everything worked flawlessly. Hope this helps out a Node/React newbie like me.
Suggestions -->
-sometimes , if you install yarn specifically using $ npm install -g yarn., this blocks all sort of scripts and react dom to install and it creates yarn.lock file which blocks it creating the scripts .
So uninstall yarn using
$ npm uninstall -g yarn
and then delete all specific folders that were created previously on the project.
And run
$npx create-react-app my-app
Happy Hacking!
ERR: Script missing
For a solution follow these steps in PowerShell
uninstall react from global
 npm uninstall -g create-react-app
Then try to update the npm and all the packages.
npm install -g npm#latest
Now create your new react app
npx create-react-app yout-app-name
consider you checked any app from git
open your package.json
under the scripts section, you will have the field called start
for the create react app,this will be like "start": "npx node index.js
But for your app, you may have customized scripts something like
"start:env": "some env configs"
just try to run cmd in your terminal npm run start:env
Dear Guys in most of our cases everything is Ok!
The most common that we do in fact, is that we start the same path in our code editor that we have already choosen for already existing folders. So while working with react make sure that you have open the right folder with right path in you code editor and then simply!
----npm start"--
It would almost in all cases if you take this little caution, Otherwise all your codes will be useless if apply this on wrong path or folder.

How to setup new reactjs project on local environment or system?

I started to learn reactjs for front end in web development. For learning purpose I install node and npm on my local system below are the versions of node and npm
node v8.11.3
npm v5.6.0
and I have run bellow command
npm init
and create pakage.json following file using command
{
"name": "loginpage",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^15.4.2",
"react-dom": "^15.4.2"
},
"devDependencies": {
"react-scripts": "0.9.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"main": "index.js",
"author": "rizwan",
"license": "ISC",
"description": ""
}
in next step i run following command install node and react dependencies
npm install
and then I run create-react-app hello-world commands but I did't find any change in my current local project folder exception pakage.json file I don't know that where I am doing mistake. Guide in right direction.
Create-react-app creates everything from scratch, you don't need to create a folder or npm init, anything like that.
Just run create-react-app my-project and you'll have everything you need in the my-project folder.
To create react app
first, install create-react-app globally
then, run these commands
create-react-app app-name
cd app-name
npm run start
I prefer to use Yarn instead of npm

Is there any default transpiler and bundler used by node package manager?

I'm new to reactJs. I'm using node package manager (NPM) for release, build and hosting process. I first ran npm install -g create-react-app command to install the command whose template helped me in creating a basic reactJs application. Now my package.json file looks like this:
{
"name": "my-react-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^15.5.4",
"react-dom": "^15.5.4"
},
"devDependencies": {
"react-scripts": "0.9.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
If you closely look at both dependencies and devDependencies section you will not be able to find anything like Babel (a transpiler) or webpack (a bundler). So I'm wondering that when I run my website using npn run start command then how my reactJs class files are getting transpiled and bundled. Is there any default transpiler and bundler used by NPM or I'm missing something in my observation?
[Update After Nicholas's comment]:
On a contrary, in a live project code base in which I work in my office, I see that these dependencies like babel-core, babel-cli, webpack etc are mentioned in devDependencies section. They are absent from dependencies section. If react-scripts already have an implicit dependency on babel-core, babel-cli, webpack etc then why do they have to be mentioned explicitly in devDependencies section? Even devDependencies can also simply do so by mentioning react-scripts they way it is happening in my test project. Isn't it? But my fellow developers aren't doing so.
react-scripts, which get's called when you run $ npm start has those transpilers/bundlers as it's own dependencies.
You won't see the dependencies of an explicitly installed module, react-scripts in your example, within your package.json. They would exist as dependencies in react-scripts module's package.json instead.
For example, have a look at the package.json of this subfolder, of that react-scripts module.
It contains a bunch of dependencies, some of them being Babel and Webpack.

Resources