Problem with deplyoing application on Heroku - 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

Related

Heroku not using cache for Yarn v3

Trying to get Heroku to use cached modules for Yarn v3 using workspaces. I have the following:
package.json:
"engines": {
"node": "16.x",
"yarn": "3.x"
},
"cacheDirectories": [
"node_modules",
"packages/components/node_modules",
"packages/lib/node_modules",
"packages/schema/node_modules",
"packages/web/node_modules",
"packages/web/.next/cache"
]
heroku-buildpack-features:
cache-native-yarn-cache=true
Heroku output:
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
USE_YARN_CACHE=true
NODE_VERBOSE=false
NODE_ENV=production
NODE_MODULES_CACHE=true
-----> Installing binaries
! You don't need to specify Yarn engine. Heroku will install the latest Yarn 1.x, so that per project version can be used. More information here: https://yarnpkg.com/getting-started/install#global-install
https://devcenter.heroku.com/articles/nodejs-support
engines.node (package.json): 16.x
engines.npm (package.json): unspecified (use default)
engines.yarn (package.json): unspecified (use default)
Resolving node version 16.x...
Downloading and installing node 16.7.0...
Using default npm version: 7.20.3
Resolving yarn version 1.22.x...
Downloading and installing yarn (1.22.11)
Using yarn 3.0.0
-----> Installing binaries
! You don't need to specify Yarn engine. Heroku will install the latest Yarn 1.x, so that per project version can be used. More information here: https://yarnpkg.com/getting-started/install#global-install
https://devcenter.heroku.com/articles/nodejs-support
engines.node (package.json): 16.x
engines.npm (package.json): unspecified (use default)
engines.yarn (package.json): unspecified (use default)
Resolving node version 16.x...
Downloading and installing node 16.7.0...
Using default npm version: 7.20.3
Resolving yarn version 1.22.x...
Downloading and installing yarn (1.22.11)
Using yarn 3.0.0
-----> Restoring cache
Loading 6 from cacheDirectories (package.json):
- node_modules
- packages/components/node_modules (not cached - skipping)
- packages/lib/node_modules
- packages/schema/node_modules
- packages/web/node_modules
- packages/web/.next/cache
<a bunch of resolve stuff>
➤ YN0000: ┌ Fetch step
➤ YN0013: │ #apollo/client#npm:3.4.7 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ #apollo/protobufjs#npm:1.2.2 can't be found in the cache and will be fetched from the remote registry
<and so on>
I've tried adding ".yarn/cache" to cacheDirectories in package.json, but it always says it's empty.
Not really sure where to go from here.
As of 9/2/2021, Heroku's nodeJS buildback doesn't fully support yarn 2. They started adding support in v173, but caching hasn't been fully addressed yet.
The underlying issue is that the buildpack doesn't properly detect that $BUILD_DIR/.yarn/cache exists and sets the environment variable YARN_CACHE_FOLDER to something other than .yarn/cache.(see
https://github.com/heroku/heroku-buildpack-nodejs/blob/752f1d5a139a800920cf5bb1bf70aad1a2954525/bin/compile#L140)
When the buildpack gets to the cache step the .yarn/cache directory doesn't actually exist.
The solution:
I was able to work around this by manually setting YARN_CACHE_FOLDER to .yarn/cache in the config vars. You can do this via the CLI by running heroku config:set YARN_CACHE_FOLDER=.yarn/cache.
Ensure you also have .yarn/cache listed in cacheDirectories.
You will know it works when the build logs show:
-----> Caching build
Saving 1 cacheDirectories (package.json):
- .yarn/cache
If it did not work there would be a (nothing to cache) note next to .yarn/cache.

Application error when trying to deploy heroku app

Deploying an app on heroku and the build succeeds but when I try to open it I get "application error" and it tells me to check the logs.
The logs:
-----> 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): unspecified
engines.npm (package.json): unspecified (use default)
Resolving node version 12.x...
Downloading and installing node 12.16.3...
Using default npm version: 6.14.4
-----> Restoring cache
Cached directories were not restored due to a change in version of node, npm, yarn or stack
Module installation may take longer for this build
-----> Installing dependencies
Installing node modules
added 0 packages in 0.033s
-----> Build
-----> Caching build
- node_modules (nothing to cache)
-----> Pruning devDependencies
up to date in 0.219s
found 0 vulnerabilities
-----> Build succeeded!
-----> Discovering process types
Procfile declares types -> (none)
Default types for buildpack -> web
-----> Compressing...
Done: 22.2M
-----> Launching...
Released v6
https://cbcv.herokuapp.com/ deployed to Heroku
Any ideas as to what I'm missing?
Please provide the logs after the build is succeeded. You've given the logs while the app was being deployed. To view the recent logs you can use heroku logs --tail.

After deploying getting internal server error on heroku

Build successfully but still getting internal server error.
Please help to fix this, build message is given below:-
-----> Node.js app detected
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NODE_VERBOSE=false
NODE_ENV=production
NODE_MODULES_CACHE=true
-----> Installing binaries
engines.node (package.json): 10.6.0
engines.npm (package.json): unspecified (use default)
Resolving node version 10.6.0...
Downloading and installing node 10.6.0...
Using default npm version: 6.1.0
-----> Restoring cache
Loading 2 from cacheDirectories (default):
- node_modules
- bower_components (not cached - skipping)
-----> Building dependencies
Installing node modules (package.json + package-lock)
audited 492 packages in 2.222s
found 0 vulnerabilities -----> Caching build
Clearing previous node cache
Saving 2 cacheDirectories (default):
- node_modules
- bower_components (nothing to cache)
-----> Pruning devDependencies
removed 66 packages and audited 355 packages in 2.11s
found 0 vulnerabilities
-----> Build succeeded!
-----> Discovering process types
Procfile declares types -> (none)
Default types for buildpack -> web
-----> Compressing...
Done: 22.6M
-----> Launching...
Released v14
https://young-forest-74580.herokuapp.com/ deployed to Heroku

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.

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"
},

Resources