[SOLVED] Self-Hosted Server on Heroku

I am trying to migrate my project to a self-hosted Moralis server on Heroku. I am following the official guideline document, as well as posts in this forum, ex. noviulian/parse-server-migration topic. There seems to be a problem with the ngrok versioning in package.json though. In the official/noviulian repository ngrok dependency is set to “^4.3.3”. I can build the project and generate build/cloud/main.js module, but can not run the server:

error_code":103,“status_code”:502,“msg”:"failed to start tunnel”.

In order to run the server successfully I need to update the ngrok package to the latest one, 5.0.0-beta.2. After that I can run the server on my local machine. All good. However, once I push my repository to Heroku I get the following error:

Error: Cannot find module */app/build/cloud/main.js’
Require stack:

  • /app/node_modules/parse-server/lib/ParseServer.js
  • /app/node_modules/parse-server/lib/index.js
    -/app/build/index.js

Apparently, ngrok version 5.0.0-beta.2 can’t build the required cloud module. I can reproduce this error on my local machine too.

Does anyone have any idea on how to solve this problem. Any help would be much appreciated.

Hi @zrco, have you tried reinstalling ngrok using the command “yarn add ngrok”? As mentioned in this post [solved] Parse server self-host (Bad Gateway)

Hey @j0n4,

Reinstalling ngrok works only on the local server, since I’ve already built the project previously. While deploying to Heroku I am building the production package with the newer ngrok version. For some reason the production package will miss the build/cloud, parse-server modules.

If it works on local server, it should also work on hereoku. Maybe if heroku has some caching for the previous builds you need to build again without the cache.

Make sure you have pushed all the required changes to heroku before running the new build.

It works locally only because I re-installed ngrok. Fresh installation with the following package.json will never work on local or Heroku servers.
{
“name”: “demo-parse-server-migration”,
“version”: “1.1.0”,
“main”: “dist/index.js”,
“private”: true,
“dependencies”: {
@codemirror/language”: “^0.20.0”,
@moralisweb3/core”: “^2.7.0”,
@moralisweb3/parse-server”: “^2.19.0”,
@types/cors”: “^2.8.12”,
@types/express”: “^4.17.14”,
@types/node”: “^18.11.9”,
“cors”: “^2.8.5”,
“dotenv”: “^16.0.1”,
“envalid”: “7.3.1”,
“express”: “^4.18.1”,
“express-rate-limit”: “^6.5.1”,
“graphql”: “^16.6.0”,
“graphql-ws”: “^5.10.1”,
“moralis”: “^2.19.0”,
“ngrok”: “^5.0.0-beta.2”,
“parse-dashboard”: “^5.0.0”,
“parse-server”: “^5.5.1”
},
“devDependencies”: {
@moralisweb3/eslint-config”: “^1.0.0”,
@typescript-eslint/eslint-plugin”: “^5.12.0”,
@typescript-eslint/parser”: “^5.12.0”,
“axios”: “^0.27.2”,
“eslint”: “^8.9.0”,
“eslint-plugin-etc”: “^2.0.2”,
“eslint-plugin-import”: “^2.26.0”,
“mongodb-runner”: “^4.9.0”,
“prettier”: “^2.7.1”,
“ts-node”: “^10.9.1”,
“typescript”: “^4.7.4”
},
“scripts”: {
“dev”: “ts-node src/index.ts”,
“start”: “node build/index.js”,
“build”: “tsc”,
“lint”: “eslint --ext .js,.ts .”,
“format”: “prettier --write ‘src/**/*.{js,ts}’”,
“dev:db-start”: “mongodb-runner start”,
“dev:db-stop”: “mongodb-runner stop”,
“gen:cloud”: “ts-node ./scripts/generateCloudCode.ts”,
“tsc”: “tsc”
},
“engines”: {
“node”: “16.20.0”,
“npm”: “9.6.7”
}
}

Can you try replacing the start command with npm i ngrok && node build/index.js ?

I think will make sure to install ngrok before running the app on heroku.

Still the same problem. Ngrok is already installed but the latest version 5.0.0-beta.2 is not compatible with migration template. Below is the build folder, you can see that cloud is not there.

In that case, can we specify the compatible ngrok version while installing through the start command?

I am not sure tbh.

I’m following this template https://github.com/noviulian/parse-server-migration and I am stuck. Re-installing ngrok is just a temporary solution since it works only if ngrok 4.3.3 was previously used to build production package. After re-installing ngrok the package.json is updated with the latest ngrok version. If I try to do a fresh installation on another computer or Heroku I am getting this error:

Error: Cannot find module */app/build/cloud/main.js’
Require stack:

  • /app/node_modules/parse-server/lib/ParseServer.js
  • /app/node_modules/parse-server/lib/index.js
    -/app/build/index.js

It seems the problem here is ngrok 4.3.3 has some problems (failed to start tunnel) and while upgrading it to 5.0.0-beta.2 solves those problems, they generate other problems (Cannot find module */app/build/cloud/main.js’)

@zrco I see in your initial description you mention
“I can build the project and generate build/cloud/main.js”
And on Heroku you get:
“Error: Cannot find module */app/build/cloud/main.js’”

At first sight it looks like Heroku is expecting a different path :thinking:
This also is a common error, please try following steps here and let us know if you are able to solve:

  1. https://stackoverflow.com/a/70597682/5500559
  2. https://devcenter.heroku.com/articles/troubleshooting-node-deploys
  3. Could you also try deploying in Heroku as a new app? There might be something cached preventing the deploy after the changes.

I was able to solve the problem by simply using a different GitHub account on my local machine. I’m not sure if this makes any sense at all. I am using Avast Premium Security that comes with a secure VPN connection that I can’t disable. I was previously trying to enable ngrok ports manually, not sure if something got blacklisted in the process.

I apologies for waisting everyone’s time. At least we know that current migration template should upgrade ngrok dependency to 5.0.0-beta.2

2 Likes