I have a react project bootstrapped using the CRA Cli. I have travis for CI and deploying on Heroku. The project has been running for about a month now. The last build was about 25 days ago and it passed. Today, when I visit this app, it is breaking. When I rebuild and re-deploy, the rebuild works, deployment too to some extent and the error
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
Since the last push 25 days ago, I have merged anything into master, so I am quite certain that there is no code that got to source control and messed things up.
This is my package.json (just the relevant parts)
"dependencies": {
"axios": "^0.18.0",
"leaflet": "^1.3.1",
"lodash": "^4.17.5",
"npm-run-all": "^4.1.2",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-leaflet": "^1.9.0",
"react-redux": "^5.0.7",
"react-scripts": "1.1.1",
"react-tabs": "^2.2.1",
"react-tabs-redux": "^2.0.1",
"redux": "^3.7.2",
"redux-thunk": "^2.2.0",
"socket.io-client": "^2.1.0",
"thunk": "0.0.1"
},
"scripts": {
"start": "npm-run-all -p watch-css start-js",
"build": "npm-run-all build-css build-js",
"start-js": "react-scripts start",
"build-js": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"test-ci": "CI=true react-scripts test --env=jsdom --ci",
"eject": "react-scripts eject",
"build-css": "node-sass-chokidar src/ -o src/ --quiet",
"watch-css": "npm run build-css && node-sass-chokidar src/ -o src/ --watch --recursive",
"lint": "./node_modules/.bin/eslint src/**/*.js",
"prettier": "prettier --write --tab-width=2 --single-quote=true \"src/**/*.{js,scss}\""
},
And this is my index.js (relevant parts only)
if (process.env.NODE_ENV === 'development') {
middleware = [logger];
}
const store = createStore(
rootReducer,
composeWithDevTools(applyMiddleware(thunk, ...middleware))
);
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root')
);
And the Procfile
web: npm i -g serve && npm run build && serve -s build
And this is the last build status
Then the logs from Heroku
From the logs, it says
INFO: Accepting connections at http://localhost:3000
Questions
What am I doing wrong here?
How come that connections are accepted at localhost but I am running a production bundle?
How do I fix it?
Please check your create server code you must have missed process.env.PORT
Heroku assigns a port dynamically which it pulls from env variable. Your code should be like this :
.listen(process.env.PORT || 3000)
Related
My react app fails to start when running in Heroku. I am using Luke McDonald's startup page located here: https://github.com/lukemcdonald/holly-react
Here is what my package.json scripts section looks like:
"scripts": {
"build": "npm run build:css && vite build",
"build:css": "postcss styles/tailwind.css -o src/assets/styles.css",
"dev": "concurrently \"npm run dev:css\" \"vite\"",
"dev:css": "postcss styles/tailwind.css -o src/assets/styles.css --watch",
"preview": "vite preview",
"predeploy": "npm run build",
"start": "concurrently \"npm run dev:css\" \"vite\"",
"deploy": "gh-pages -d dist"
},
When I push to heroku, the build succeeds. But it to fail to start:
app[web.1]: /tmp/start-497558d9.sh: 1: concurrently: not found
heroku[web.1]: Process exited with status 127
heroku[web.1]: State changed from starting to crashed
I added concurrently to my dependencies, to no avail
"dependencies": {
"clsx": "^1.1.1",
"firebase": "^9.9.3",
"gh-pages": "^4.0.0",
"postcss-import": "^14.1.0",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-router-dom": "^6.3.0",
"scrollreveal": "^4.0.9",
"concurrently": "^7.3.0"
},
"devDependencies": {
"#tailwindcss/forms": "^0.5.2",
"#tailwindcss/typography": "^0.5.2",
"#vitejs/plugin-react": "^1.3.2",
"autoprefixer": "^10.4.7",
"concurrently": "^7.3.0",
"eslint": "^8.16.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.30.0",
"eslint-plugin-react-hooks": "^4.5.0",
"postcss": "^8.4.14",
"postcss-cli": "^9.1.0",
"prettier": "^2.6.2",
"prettier-plugin-tailwindcss": "^0.1.11",
"tailwindcss": "^3.0.24",
"vite": "^2.9.9"
}
Don't try to run concurrently \"npm run dev:css\" \"vite\" on Heroku. That command is intended for development environments (such as your local machine).
You are likely trying to serve the production build of your app, which does not require concurrently at all. Just run npm run preview, which runs vite preview, which -- as of Vite 3 -- uses sirv to serve the build output directory.
However, you don't necessarily need to use vite preview. You could use any other HTTP server pointed at the build output directory (e.g., zeit/serve or http-server).
I'm using a parcel bundler instead of a react-scripts which uses npm run build-prod instead of npm run build but it doesn't create a build folder instead they all in a dist folder so i changed the deploy script in the package.json to "deploy": "gh-pages -d dist" instead of the standard "deploy": "gh-pages -d build" which will give an error saying build script is missing , after i tried deploying this to git hub pages but i get an empty screen
"scripts": {
"predeploy": "npm run build-prod",
"deploy": "gh-pages -d dist",
"clean": "rm dist/bundle.js",
"start": "parcel src/index.html",
"build-prod": "parcel build src/index.html"
},
"dependencies": {
"node-sass": "^7.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.3.0"
},
"devDependencies": {
"#babel/core": "^7.18.5",
"#babel/preset-env": "^7.18.2",
"#babel/preset-react": "^7.17.12",
"gh-pages": "^4.0.0",
"parcel-bundler": "^1.12.5",
"prettier": "^2.7.1"
}
According the the Parcel docs here, you need to specify the --dist-dir flag.
Change your "build-prod" script to this:
"build-prod": "parcel build src/index.html --dist-dir build"
Now the output directory for your parcel build will go to build instead of dist so you can change your "deploy" script back to this:
"deploy": "gh-pages -d build"
I'm trying to migrate react-scripts from my current version (1.1.4) to the latest 3.0.1 for obvious reasons, but I'm having a hell of a time.
Here's my current, build successful package.json
{
"name": "name",
"version": "0.1.0",
"homepage": ".",
"private": true,
"dependencies": {
"ajv": "^6.9.1",
"axios": "^0.18.0",
"axios-debug": "0.0.4",
"date-fns": "^1.30.1",
"formik": "1.2.0",
"history": "4.7.2",
"moment": "2.22.2",
"localforage": "1.7.3",
"prettier": "1.14.2",
"react": "^16.8.1",
"react-bootstrap": "0.32.4",
"react-checkbox-group": "4.0.1",
"react-datetime": "2.15.0",
"react-dom": "^16.3.2",
"react-render-debugger": "1.0.2",
"react-router-dom": "4.3.1",
"react-scripts": "1.1.4",
"semantic-ui-css": "^2.4.1",
"semantic-ui-react": "^0.87.1",
"styled-components": "^4.2.0",
"react-router-hash-link": "1.2.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
So I'm using npm so running npm install --save --save-exact react-scripts#3.0.1 installs the new react-scripts version, everything is updated correctly. I updated a few other packages that were needed as deps. No security vulnerabilities, everything was clean and installed correctly.
I'm using maven as a build system to build my app, once it tries to execute npm run build it fails on react-scripts build
The debug log is super unhelpful. The only error displayed is /node_modules/.bin/react-scripts: Permission denied
I've tried changing the permissions using chmod +x /node_modules/.bin/react-scripts but no luck.
I've tried deleting node_modules several times and reinstalling the modules using npm ci. Just about any issue I've found on github I've tried.
I'm not sure what else could be wrong.
Using node v11.9.0 and npm 6.5.0
Do I need to update in smaller version increments? I'm really at a loss
EDIT:
Something is wrong with npm in my case. Manually updating the package versions in package.json seems to work for now... I need to figure out why npm is broken for me
So I am looking at my package.json file - and nothing looks particularly crazy:
{
"name": "application_name",
"version": "0.1.0",
"private": true,
"dependencies": {
"bootstrap-toggle": "^2.2.2",
"classnames": "^2.2.6",
"html-react-parser": "^0.4.6",
"jquery": "^3.3.1",
"react": "^16.4.1",
"react-bootstrap-toggle": "^2.3.1",
"react-cookie": "^3.0.4",
"react-dom": "^16.5.2",
"react-load-script": "0.0.6",
"react-router-dom": "^4.3.1",
"react-scripts": "1.1.4",
"react-timer-mixin": "^0.13.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build && robocopy .\\build ..\\www /MIR",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
I've tried npm install, npm install --production and npm install --express
No matter what npm command I write, I get the following:
added 1425 packages from 862 contributors and audited 14585 packages in 15.876s
It ultimately is 202M - this can't be right, that's a HUGE number of modules
This is for a React project I am working on.
I only made this question because none of the other answers seemed to work for my situation.
Is there a solution to this problem? I am intending on compiling this into a mobile app and 202M is a huge footprint for what is a pretty simple app.
202Mb is almost completely occupied with development dependencies, react-scripts.
react-scripts is a bundle consisting Webpack and other tools that are necessary to run the project. It is provided by Create React App, which is just an executable that creates boilerplate project with react-scripts:
This package includes scripts and configuration used by Create React
App.
node_modules size is adequate for complex configuration that CRA sets up. It doesn't affect the size of compiled application.
./node_modules/react-dom/cjs/react-dom.development.js
Module not found: Can't resolve 'schedule' in 'C:\Users\adcal\dvmtn7\myapp\node_modules\react-dom\cjs'
this same error has happened three create-react-apps in a row. It works at first and then just randomly breaks.
I have only installed modules via npm. Here's the package.json
{
"name": "myapp",
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.18.0",
"dotenv": "^6.0.0",
"express": "^4.16.3",
"express-session": "^1.15.6",
"massive": "^5.3.0",
"react": "^16.5.0",
"react-dom": "^16.5.0",
"react-redux": "^5.0.7",
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"react-scripts": "1.1.5",
"redux": "^4.0.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
Update: I have the "schedules" npm installed in the projects node module folder. Why is it still throwing this error though?
(It happens in all of my projects now.)
Update to the update: I reinstalled create-react-app globally it fixed it.
I think the reason for this error is that there was a problem installing or updating a module.
I solved the problem in the following ways.
Remove package-lock.json and node_modules folder.
Run the npm install command to install a package again.
Run the yarn start command to confirm that the error has been resolved.
It appears that schedule got moved out of react in a later version.
Try
npm install scheduler --save
or updating react
https://www.npmjs.com/package/scheduler