/bin/sh: 1: go: not found when pushing to heroku - go

I'm trying to use React Frontend and Go Backend language.
I have to Go installed locally and I can run commands like go run main.go or go build. But when I try to push to Heroku, I get the following error:
$ rm -rf index && go build -o index
remote: /bin/sh: 1: go: not found
remote: error Command failed with exit code 127.
remote: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
remote: error Command failed with exit code 127.
remote: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
remote:
remote: -----> Build failed
This is my package.json:
{
"name": "fullstack-course",
"version": "1.0.0",
"description": "",
"main": "index.go",
"scripts": {
"client": "rm -rf build/ && webpack --env.mode production",
"server": "rm -rf index && go build -o index",
"start": "./index",
"heroku-postbuild": "yarn run client && yarn run server"
},
"engines": {
"node": "10.x",
"npm": "6.9.x",
"yarn": "1.x"
},
"repository": {
"type": "git",
},
"author": "",
"license": "ISC",
"dependencies": {...}
}
Why when running locally it works, but when pushing it to Heroku it fails?
How can I fix this?
Thanks

Related

Problem with deplyoing application on Heroku

I'm new to Heroku
I have been trying to deploy my app to Heroku but I'm having an issue which I can't resolve
My build passes and the app gets deployed but there is an error which I can't find nor resolve
I'm not really sure where to look nor what to look for since I'm literally too new to Heroku
Here is my build log
-----> Node.js app detected
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NODE_ENV=production
NODE_MODULES_CACHE=true
NODE_VERBOSE=false
-----> Installing binaries
engines.node (package.json): 12.x
engines.npm (package.json): 6.x
Resolving node version 12.x...
Downloading and installing node 12.18.3
Bootstrapping npm 6.x (replacing 6.14.6)...
npm 6.x installed
-----> Restoring cache
- node_modules
-----> Installing dependencies
Installing node modules
added 39 packages in 1.246s
-----> Build
-----> Caching build
- node_modules
-----> Pruning devDependencies
audited 39 packages in 0.584s
1 package is looking for funding
run `npm fund` for details
found 0 vulnerabilities
-----> Build succeeded!
-----> Discovering process types
Procfile declares types -> (none)
Default types for buildpack -> web
-----> Compressing...
Done: 23.4M
-----> Launching...
Released v5
https://ferit-virtual-classroom.herokuapp.com/ deployed to Heroku
And here is my package.json
{
"name": "ferit-bot",
"version": "1.0.0",
"description": "",
"publishConfig": { "registry": "https://npm.pkg.github.com/" },
"author": "JaVolimKatarinu",
"license": "ISC",
"dependencies": {
"discord.js": "^12.1.1",
"mysql2": "^2.1.0",
"node-fetch-npm": "^2.0.4"
},
"engines":{
"node": "12.x",
"npm": "6.x"
},
"scripts": {
"start": "main.js"
}
}
I have searched for a potential answer on Heroku support but without any luck
Thank you for reading and I would be really glad for a helpful answer
EDIT:All good, I have managed to deploy the app and its working
Thanks for help
The scripts in package-json file is not properly setup.
There must always be a start command which can be anything to be run in the terminal, but for yours, the script should be
"scripts": {
"start": "node main.js"
}
node keyword is ignored, thats why?
did you add a Procfile ?
web: node main.js

Heroku nodejs build failing: "Invalid semver requirement"

I'm having a heap of trouble deploying my nodejs app to heroku. While it works perfectly for an initial build (to an empty application in heroku) any subsequent updates that I push fail.
I have defined the node version as "8.9.x", but if I define the exact version number of the latest version, it still fails - saying that "8.9.4" is not a valid semantic version.
If I take the engines section out of my package.json entirely, it tries to resolve "8.x" and then says that "8.x" isn't a valid semantic version!
Is there anything else that I could stuff up in my package.json to cause this? Or can anything outside the package.json be causing this?
Here's the output when pushing to the heroku git repo:
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Deleting 2 files matching .slugignore patterns.
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote: NPM_CONFIG_LOGLEVEL=error
remote: NPM_CONFIG_PRODUCTION=true
remote: NODE_VERBOSE=false
remote: NODE_ENV=production
remote: NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote: engines.node (package.json): 8.9.x
remote: engines.npm (package.json): 5.6.x
remote:
remote: Resolving node version 8.9.x...
remote: Error: Invalid semantic version "8.9.x"
remote:
remote: -----> Build failed
remote:
remote: ! Invalid semver requirement
remote:
remote: Node, Yarn, and npm adhere to semver, the semantic versioning convention
remote: popularized by GitHub.
remote:
remote: http://semver.org/
remote:
remote: However you have specified a version requirement that is not a valid
remote: semantic version.
remote:
remote: https://kb.heroku.com/why-is-my-node-js-build-failing-because-of-an-invalid-semver-requirement
remote:
remote: ! Push rejected, failed to compile Node.js app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to [app name].
remote:
And here is my package.json
{
"name": "[REDACTED]",
"version": "3.4.4",
"description": "[REDACTED]",
"main": "index.js",
"engines": {
"node": "8.9.x",
"npm": "5.6.x"
},
"scripts": {
"test": "index.js",
"start": "node index.js"
},
"repository": {
"type": "git",
"url": "git+https://[REDACTED]"
},
"author": "jasonalex",
"license": "SEE LICENSE IN LICENSE",
"bugs": {
"url": "https://[REDACTED]"
},
"homepage": "https://[REDACTED]",
"dependencies": {
"#google-cloud/logging-winston": "^0.7.0",
"#google-cloud/storage": "^1.5.2",
"#google-cloud/trace-agent": "^2.4.1",
"body-parser": "^1.18.2",
"cors": "^2.8.4",
"cron": "^1.3.0",
"express": "^4.16.2",
"filereader": "^0.10.3",
"firebase-admin": "^5.8.1",
"jsonwebtoken": "^8.1.1",
"lodash": "^4.17.4",
"mailgun-js": "^0.14.2",
"moment": "^2.20.1",
"multer": "^1.3.0",
"pdfkit": "^0.8.3",
"pdfmake": "github:bpampuch/pdfmake",
"twilio": "^3.11.1",
"websocket-driver": ">=0.5.1",
"winston": "^2.4.0",
"xmlhttprequest": "^1.8.0"
},
"devDependencies": {
"babel-eslint": "^7.2.3",
"eslint": "^4.16.0",
"eslint-plugin-react": "^7.5.1",
"localtunnel": "^1.8.3"
}
}
Okay well I feel a bit silly now - in my case i had added a config var in my heroku settings called 'platform' which was interfering with the official nodejs buildpack.
Removing/renaming this variable has cleared the problem right up.

Grunt not found error when deploying to Heroku

I'm getting the error below:
remote: sh: 1: grunt: not found
when I'm deploying my code to Heroku server.
My install scripts in package.json is like:
"scripts": {
"postinstall": "grunt heroku:production && bower install",
"test": "mocha",
"start": "node app.js"
}
I set heroku config like
heroku config:set NPM_CONFIG_PRODUCTION=false
Also I made
export BUILDPACK_URL=https://github.com/mbuchetics/heroku-buildpack-nodejs-grunt.git
but nothing has changed. I have grunt and grunt-cli in both dependencies and devDependencies.
So where am I wrong?

Heroku node_modules not cached

I have toplevel package.json where I set cacheDirectories as per https://devcenter.heroku.com/articles/nodejs-support#custom-caching
"scripts": {
"start": "npm --prefix frontend start && npm --prefix mockserver start",
},
"dependencies": {
},
"devDependencies": {
},
"cacheDirectories": ["frontend/node_modules", "mockserver/node_modules"],
...
So no dependencies in toplevel, but I have frontend/package.json and mockserver/package.json with a lot of dependencies that get installed in their respective node_modules. This is how the respective package.jsons look like (for example mockserver):
"scripts": {
"start": "npm install && npm run build && node dist/server.js",
},
dependencies...
devdependencies...
This works fine and deploys, but it does not cache the the two node_modules defined to be cached.
Here is the output from heroku build:
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NPM_CONFIG_PRODUCTION=true
NODE_VERBOSE=false
NODE_ENV=demo
NODE_MODULES_CACHE=true
npm scripts will see NODE_ENV=production (not 'demo')
https://docs.npmjs.com/misc/config#production
-----> Installing binaries
engines.node (package.json): 7.10.0
engines.npm (package.json): unspecified (use default)
Downloading and installing node 7.10.0...
Using default npm version: 4.2.0
-----> Restoring cache
Loading 2 from cacheDirectories (package.json):
- frontend/node_modules (not cached - skipping)
- mockserver/node_modules (not cached - skipping)
-----> Building dependencies
Installing node modules (package.json)
-----> Caching build
Clearing previous node cache
Saving 2 cacheDirectories (package.json):
- frontend/node_modules (nothing to cache)
- mockserver/node_modules (nothing to cache)
-----> Build succeeded!
Just to note that the two node_modules were installed in the previous build but it says (not cached - skipping).
Thanks in advance!
I got the answer here: https://github.com/heroku/heroku-buildpack-nodejs/issues/435
In summary, I should have used heroku-postbuild instead of start script to install custom dependencies. And use start only as application starting command.
Top level package.json
"scripts": {
"heroku-postbuild": "npm --prefix frontend run installAndCompile && npm --prefix mockserver run installAndCompile",
"start": "npm --prefix mockserver start"
},
Subproject's package.json
"scripts": {
"installAndCompile": "npm install && npm run compile"
},

Heroku ruby app - run gulp build process after deploy

I have a ruby application hosted on Heroku, it's a Ruby Sinatra app and I am using gulp to build my sass and coffee files for the client. I have added a postinstall script to my package.json and I have all my gulp dependencies listed but no npm install happens, probably because the app is a ruby application and npm is not on the deploy radar? Here's what my package.json looks like:
"dependencies": {
"gulp": "^3.9.1",
"gulp-coffee": "^2.3.3",
"gulp-filter": "^4.0.0",
"gulp-plumber": "^1.1.0",
"gulp-sass": "^3.0.0",
"browser-sync": "2.16.0"
},
"devDependencies": {},
"scripts": {
"postinstall": "npm install && gulp build"
}
What am I missing? Is it not possible to run npm and ruby on the same container?
I ended up finding the answer here: https://devcenter.heroku.com/articles/using-multiple-buildpacks-for-an-app
What I needed was to add a nodejs buildpack so that npm install would happen along with the postinstall script. Add a node buildpack using the Heroku CLI like this:
heroku buildpacks:add --index 1 heroku/nodejs
I also removed npm install from my postinstall hook because it happens automatically with the node buildpack.

Resources