Something wrong with my heroku deployment - node.js

`NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client`
remote: npm ERR! Exit status 254
remote: npm ERR!
remote: npm ERR! Failed at the walking-bucket#1.0.0 heroku-postbuild script.
This is the error I get when I try to deploy my express/React app to heroku, any ideas what is going wrong?
edit: package.json with build script:
{
"name": "walking-bucket",
"version": "1.0.0",
"description": "basketball shot journal log",
"main": "server.js",
"scripts": {
"client-install": "npm install --prefix client",
"start": "node server.js",
"server": "nodemon server.js",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
},
"author": "",
"license": "ISC",
"dependencies": {
"bcrypt": "^3.0.2",
"bcrypt-nodejs": "0.0.3",
"body-parser": "^1.18.3",
"concurrently": "^4.1.0",
"express": "^4.16.4",
"express-session": "^1.15.6",
"mongoose": "^5.3.14",
"passport": "^0.4.0",
"passport-local": "^1.0.0",
"passport-local-mongoose": "^5.0.1"
},
"devDependencies": {
"nodemon": "^1.18.7"
}
}

Got my solution with the build command
"build": "react-scripts build"
from the create-react-app package.json

Related

Failed build on Heroku with custom heroku-postbuild script

I have two main folders for my project: server and client. Heroku only seems to care about the server/package.json. Deployment is going fine until it returns an error when the process runs the "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client" command from package.json.
Here's the error message from the console:
-----> Build
remote: Running heroku-postbuild
remote:
remote: > server#1.0.0 heroku-postbuild
remote: > npm install --prefix client && npm run build --prefix client
remote:
remote: npm ERR! code ENOENT
remote: npm ERR! syscall open
remote: npm ERR! path /tmp/build_25b1f86c/client/package.json
remote: npm ERR! errno -2
remote: npm ERR! enoent ENOENT: no such file or directory, open '/tmp/build_25b1f86c/client/package.json'
remote: npm ERR! enoent This is related to npm not being able to find a file.
remote: npm ERR! enoent
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.3i4hV/_logs/2022-08-05T15_34_56_961Z-debug-0.log
remote:
remote: -----> Build failed
Here's server/package.json:
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"engines": {
"node": "16.16.0",
"npm": "8.11.0"
},
"scripts": {
"start": "node index.js",
"server": "nodemon index.js",
"client": "npm run start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.20.0",
"concurrently": "^7.3.0",
"cookie-session": "^2.0.0",
"express": "^4.18.1",
"mongoose": "^6.5.0",
"nodemon": "^2.0.19",
"passport": "^0.5.3",
"passport-google-oauth20": "^2.0.0",
"stripe": "^10.0.0"
}
}
Here's client/package.json:
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.16.4",
"#testing-library/react": "^13.3.0",
"#testing-library/user-event": "^13.5.0",
"axios": "^0.27.2",
"http-proxy-middleware": "^2.0.6",
"materialize-css": "^1.0.0-rc.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-redux": "^8.0.2",
"react-router-dom": "^5.3.3",
"react-scripts": "5.0.1",
"react-stripe-checkout": "^2.6.3",
"redux": "^4.2.0",
"redux-thunk": "^2.4.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
I tried removing parts of "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client" to shorten it into "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false" in other deployments and it worked. It seems "npm install --prefix client && npm run build --prefix client" is the part not working in the heroku-postbuild script.
Would you have any idea how to fix this? Thanks!
OK, found it. My course TA helped me figure it out. The solution below worked.
In my Github repo called server, the client directory was completely missing, so, the Heroku server was likely having the same problem. And it did. I had to delete the .git directory in the client so version control doesn't think this is a submodule. From the root repository:
cd client
rm -r .git
git rm --cached .
cd ..
git add client
git commit -m "remove submodule"
git push origin main
git push heroku main

ENOENT: no such file or directory, open 'C:\Users\username\package.json' when need to run docker and nodejs

i need to build image from nodejs project . but when i run this command :
docker run image-name
it show me this error :
C:\Users\username\package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\username\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
this is my docker file :
FROM node:14.16.1
ENV NODE_ENV=production
WORKDIR /
COPY ["package.json", "package-lock.json*", "./"]
RUN npm cache clean --force && npm install
COPY . .
EXPOSE 3000
CMD npm run start
and this is package.json :
{
"name": "Profile",
"version": "1.0.0",
"description": "",
"main": "dist/index.js",
"scripts": {
"build": "rimraf dist && tsc",
"preserve": "npm run build",
"serve": "cross-env NODE_ENV=development concurrently \"tsc --watch\" \"nodemon -q dist/index.js\"",
"prestart": "npm run build",
"start": "cross-env NODE_ENV=production node dist/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"#types/body-parser": "^1.19.1",
"body-parser": "^1.19.0",
"cross-env": "^7.0.3",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"helmet": "^4.6.0",
"mongoose": "^5.13.7",
"rimraf": "^3.0.2"
},
"devDependencies": {
"#types/express": "^4.17.13",
"#types/mongoose": "^5.11.97",
"#types/node": "^16.7.1",
"concurrently": "^6.2.1",
"nodemon": "^2.0.12",
"ts-node": "^10.2.1",
"typescript": "^4.3.5"
}
}
whats the problem ?? how can i solve this problem ??
Edit
OS : Windows 10
Command For Build Image : docker build -tag profile-srv
Project Structure :
I guess:
FROM node:14.16.1
ENV NODE_ENV=production
WORKDIR /
COPY package.json .
COPY package-lock.json* .
RUN npm cache clean --force
RUN npm install
COPY . .
EXPOSE 3000
CMD npm run start

Why My server is not running using the npm run start:prod ? Below is packgae.json file

When I try to run in the production mode, then I got the below error:
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! shop-api#1.0.0 start:prod: `NODE_ENV=production nodemon server.js`
npm ERR! Exit status 1
{
"name": "shop-api",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start:dev": "nodemon server.js",
"start:prod": "NODE_ENV=production nodemon server.js",
"debug": "ndb server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"mongoose": "^5.9.6",
"morgan": "^1.10.0",
"ndb": "^1.1.5"
},
"devDependencies": {
"nodemon": "^2.0.2"
}
}
I ran into the same problem.
Just do this:
"start": "nodemon server.js",
"start:prod": "NODE_ENV=production npm start"
After adding "start:prod": "SET NODE_ENV=production && nodemon server.js" in package.json instead of "start:prod": "NODE_ENV=production nodemon server.js".Then my code is running
I ran into same issue.
this will solve it for you
"start:prod": "SET NODE_ENV=production && nodemon server.js"
I experience the same problem, just run this command
//=> npm start prod this work for me 100%
here is my package.json file
"start": "nodemon server.js",
"start:prod": "NODE_ENV=production nodemon server.js",

How to run nodemon + ts-node + typescript altogether without having to install ts-node or npx globally?

I have the following in my package.json:
"scripts": {
"serve-fake-api": "nodemon fake-api/server.ts --watch 'fake-api/*.*'",
"serve-vue": "vue-cli-service serve",
"serve": "concurrently -k \"npm run serve-fake-api\" \"npm run serve-vue\"",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
and I would like to rewrite "serve-fake-api": "nodemon --exec 'ts-node' fake-api/server.ts --watch fake-api/*.*", but without having to install ts-node or npx globally.
How can I achieve that?
I have come across ts-node-dev recently, which fuses together ts-node and node-dev.
No configuration required. CLI arguments are the combination of the ones ts-node and node-dev accepts, and a couple of its own on top of that.
Run like this:
"start": "tsnd fake-api/server.ts"
You can just install nodemon and ts-node locally as dev dependency:
npm install -D ts-node nodemon
Now, when you run npm scripts they will use your local version by default:
In addition to the shell’s pre-existing PATH, npm run adds
node_modules/.bin to the PATH provided to scripts. Any binaries
provided by locally-installed dependencies can be used without the
node_modules/.bin prefix
I managed to run everything with the packages.json below:
{
"name": "rm-combo",
"version": "0.1.0",
"private": true,
"scripts": {
"serve-fake-api": "nodemon fake-api/index.ts --watch fake-api/*.*",
"serve-vue": "vue-cli-service serve",
"serve": "concurrently -k \"npm run serve-fake-api\" \"npm run serve-vue\"",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"#types/node": "^12.12.7",
"axios": "~0.19.0",
"devextreme": "19.2.3",
"devextreme-vue": "19.2.3",
"element-ui": "~2.8.2",
"oidc-client": "~1.9.1",
"vue": "^2.6.10",
"vue-class-component": "^7.1.0",
"vue-property-decorator": "^8.3.0",
"vue-router": "^3.1.3",
"vuetify": "^2.1.10",
"vuex": "^3.1.2",
"vuex-class": "^0.3.2"
},
"devDependencies": {
"#types/express": "^4.17.2",
"#types/json-server": "^0.14.2",
"#vue/cli-plugin-typescript": "^4.0.5",
"#vue/cli-service": "^4.0.5",
"concurrently": "^5.0.0",
"devextreme-cldr-data": "^1.0.2",
"globalize": "^1.4.2",
"json-server": "^0.15.1",
"node-sass": "^4.13.0",
"nodemon": "^1.19.4",
"sass-loader": "^8.0.0",
"ts-node": "^8.5.0",
"typescript": "^3.7.2",
"vue-template-compiler": "^2.6.10"
}
and ts features supported with doing that trick there: https://stackoverflow.com/a/59126595/4636721

error while pushing node js project to heroku

I am getting this error while I am trying to push my project to heroku. Backend is writtend in nodeJS, frontend in React. I think the problem is heroku-postbuild, because if I remove it, push works. I was searching for it but still I have no idea what is the reason. Can somebody help me?
/tmp/build_7504975f08f330415cdefb27437cfad9/node_modules/.bin/node: 1: /tmp/build_7504975f08f330415cdefb27437cfad9/node_modules/.bin/node: MZ����#: not found
/tmp/build_7504975f08f330415cdefb27437cfad9/node_modules/.bin/node: 1: /tmp/build_7504975f08f330415cdefb27437cfad9/node_modules/.bin/node: Syntax error: word unexpected (expecting ")")
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! project#1.0.0 heroku-postbuild: `cd client && npm install && npm run build`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the project#1.0.0 heroku-postbuild 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! /tmp/npmcache.W89m8/_logs/2018-11-13T21_37_22_676Z-debug.log
-----> Build failed
We're sorry this build is failing! You can troubleshoot common issues here:
https://devcenter.heroku.com/articles/troubleshooting-node-deploys
Some possible problems:
- node_modules checked into source control
https://blog.heroku.com/node-habits-2016#9-only-git-the-important-bits
- Node version not specified in package.json
https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
Love,
Heroku
! Push rejected, failed to compile Node.js app.
! Push failed
package.json (server)
{
"name": "project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node server.js",
"server": "nodemon server.js",
"client-install": "npm install --prefix client",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"heroku-postbuild": "cd client && npm install && npm run build"
},
"author": "",
"license": "ISC",
"dependencies": {
"concurrently": "^4.0.1",
"express": "^4.16.4",
"jsonwebtoken": "^8.3.0",
"mongoose": "^5.3.4",
"node": "^8.10.0",
"nodemon": "^1.18.4",
"passport": "^0.4.0",
"passport-jwt": "^4.0.0",
"react-scripts": "1.0.11",
},
"devDependencies": {
"nodemon": "^1.18.4",
"react-scripts": "1.0.11"
}
}
package.json (client)
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"parallelshell": "^3.0.2",
"react-dom": "^16.5.2",
"react-redux": "^5.0.7",
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"react-router-redux": "^4.0.8",
"react-scripts": "2.0.5",
"socket.io-client": "^1.7.3",
},
"scripts": {
"start": "parallelshell \"react-scripts start\" \"sass --watch src/styles/scss:src/styles/css --style compressed\"",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"sass": "sass --watch src/styles/scss:src/styles/css --style compressed",
"sass-nw": "sass src/styles/scss:src/styles/css"
},
"proxy": "http://localhost:5000/",
}
I ran into the similar error while troubleshooting a project. I resolved it by using the suggestions from the prompt.
Some possible problems:
- node_modules checked into source control
https://blog.heroku.com/node-habits-2016#9-only-git-the-important-bits
- Node version not specified in package.json
https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
So try do a "rm -rf node_modules" in the root directory if you checked node_modules into the repository. Heroku will install node_modules in the deployed environment and does not need your checked in version.

Resources