NestJS (Nx workspace) build failing on Heroku - heroku

I'm trying to deploy a NestJS app (in Nx workspace) on Heroku, but the deploy is failing with error:
2021-12-24T11:03:17.280952+00:00 app[web.1]: at /app/node_modules/#nestjs/mongoose/dist/factories/definitions.factory.js:26:38
2021-12-24T11:03:17.280953+00:00 app[web.1]: at Array.forEach (<anonymous>)
2021-12-24T11:03:17.280953+00:00 app[web.1]: at Function.createForClass (/app/node_modules/#nestjs/mongoose/dist/factories/definitions.factory.js:25:86)
2021-12-24T11:03:17.280954+00:00 app[web.1]: at Function.createForClass (/app/node_modules/#nestjs/mongoose/dist/factories/schema.factory.js:9:75)
2021-12-24T11:03:17.280954+00:00 app[web.1]: at Object.89 (/app/dist/apps/api/main.js:1:4717)
2021-12-24T11:03:17.280954+00:00 app[web.1]: at o (/app/dist/apps/api/main.js:1:12427)
2021-12-24T11:03:17.280955+00:00 app[web.1]: at Object.812 (/app/dist/apps/api/main.js:1:5865)
2021-12-24T11:03:17.280955+00:00 app[web.1]: at o (/app/dist/apps/api/main.js:1:12427)
2021-12-24T11:03:17.424198+00:00 heroku[web.1]: Process exited with status 1
2021-12-24T11:03:17.602083+00:00 heroku[web.1]: State changed from starting to crashed
I have seen some Mongoose issues and they don't seem to be the problem here, since the packages have since gotten multiple updates.
Edit:
After running the app from the Heroku console I got a more explicit error:
/app/node_modules/#nestjs/mongoose/dist/factories/definitions.factory.js:43
optionsOrType = isClass ? optionsOrType : optionsOrType();
^
TypeError: Class constructors cannot be invoked without 'new'
at Function.inspectTypeDefinition (/app/node_modules/#nestjs/mongoose/dist/factories/definitions.factory.js:43:55)
at Function.inspectTypeDefinition (/app/node_modules/#nestjs/mongoose/dist/factories/definitions.factory.js:52:39)
at /app/node_modules/#nestjs/mongoose/dist/factories/definitions.factory.js:26:38
at Array.forEach (<anonymous>)
at Function.createForClass (/app/node_modules/#nestjs/mongoose/dist/factories/definitions.factory.js:25:86)
at Function.createForClass (/app/node_modules/#nestjs/mongoose/dist/factories/schema.factory.js:9:75)
at Object.89 (/app/dist/apps/api/main.js:1:4301)
at o (/app/dist/apps/api/main.js:1:12011)
at Object.812 (/app/dist/apps/api/main.js:1:5449)
at o (/app/dist/apps/api/main.js:1:12011)

I had the same problem and it was caused by an upgrade of nrwl/nx to 13.3.1.
A downgrade of nrwl/nx to 13.2.4 fixed it.
So it seems that nx 13.3.0 introduced a dependency update which breaks the application.

Related

NameError - unitilaized constant - only in production

I have a ruby on rails app that is hosted on heroku. When I try to create an item running it in "development" mode, everything works great and there are no issues. However, when I switch the app to run in "production" mode I'm getting the following.
This was a Ruby 2.2.x upgraded to 2.5.x and rails 4.1 upgraded to 5.2.
Any ideas or suggestions on why this is failing in production but works fine in development?
Started POST "/items" for 1.2.3.4 at 2020-10-19 03:22:06 +0000
2020-10-19T03:22:06.870055+00:00 app[web.1]: Processing by ItemController#create as HTML
2020-10-19T03:22:06.870358+00:00 app[web.1]: Parameters: {###Redacted##}
2020-10-19T03:22:06.926046+00:00 app[web.1]: Completed 500 Internal Server Error in 54ms (ActiveRecord: 15.8ms)
2020-10-19T03:22:06.999133+00:00 app[web.1]: I, [2020-10-19T03:22:06.998984 #11] INFO -- : Sending event 18b887c876d4524b5cd46849a98aaeb1 to Sentry
2020-10-19T03:22:07.271068+00:00 app[web.1]:
2020-10-19T03:22:07.271478+00:00 app[web.1]: NameError (uninitialized constant #<Class:0x0000567238d68165>::Slug):
2020-10-19T03:22:07.276183+00:00 app[web.1]:
2020-10-19T03:22:07.276248+00:00 app[web.1]: app/models/item.rb:305:in `name_to_slug'
2020-10-19T03:22:07.276248+00:00 app[web.1]: app/models/item.rb:293:in `generate_slug'
I tracked this back to a custom class that was located in the "lib" folder. Moving from Rails 4 to 5 it seems like some behaviors changed with loading custom classes which needed to be accounted for:
https://gist.github.com/maxivak/381f1e964923f1d469c8d39da8e2522f

Why is the bot on Heroku Server not responding?

I programmed a simple bot that is connected to Google Sheets API. It asks a few questions to the user and stores it in the Sheet I have. When I use bot.polling it works fine, but I was trying the webhook so I could use Heroku to have my bot running 24/7.
I introduced the code:
#server.route('/' + token, methods=['POST'])
def getMessage():
bot.process_new_updates([telebot.types.Update.de_json(request.stream.read().decode("utf-8"))])
return "!", 200
#server.route("/")
def webhook():
bot.remove_webhook()
bot.set_webhook(url = '<Heroku App Link>' + token)
return "!", 200
if __name__ == "__main__":
server.run(host="0.0.0.0", port = int(os.environ.get('PORT', 5000)))
I have the requirements.txt file and the Procfile that currently is like this:
web: python3 bot.py
I tried a bunch of things in the Procfile but this is the only one that didn't gave an error.
When I saw the log this is what I got:
2019-09-24T10:18:54.369238+00:00 heroku[web.1]: State changed from crashed to starting
2019-09-24T10:19:04.416777+00:00 heroku[web.1]: Starting process with command `python3 bot.py`
2019-09-24T10:19:09.868915+00:00 heroku[web.1]: State changed from starting to up
2019-09-24T10:19:09.790773+00:00 app[web.1]: * Serving Flask app "bot" (lazy loading)
2019-09-24T10:19:09.790800+00:00 app[web.1]: * Environment: production
2019-09-24T10:19:09.790853+00:00 app[web.1]: WARNING: This is a development server. Do not use it in a production deployment.
2019-09-24T10:19:09.790940+00:00 app[web.1]: Use a production WSGI server instead.
2019-09-24T10:19:09.790991+00:00 app[web.1]: * Debug mode: off
2019-09-24T10:19:09.799470+00:00 app[web.1]: * Running on http://0.0.0.0:57826/ (Press CTRL+C to quit)
2019-09-24T10:19:15.000000+00:00 app[api]: Build succeeded
Can anyone help me understand why the bot doesn't answer any commands?

meanjs 0.4.0 not working when deployed to Heroku

I've just tried the meanjs 0.4.0 in local host and runs fine but when I deploy to heroku link to app and try the "Sign up" option I get this in the navegator console:
POST https://meanjsapptest.herokuapp.com/api/auth/signup 503 (Service Unavailable)
and when I write the comand heroku logs in the CLI I get:
2017-06-06T04:15:35.152983+00:00 app[web.1]: (node:16) DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html
2017-06-06T04:15:35.153005+00:00 app[web.1]: crypto.js:635
2017-06-06T04:15:35.153006+00:00 app[web.1]: throw new TypeError(
2017-06-06T04:15:35.153006+00:00 app[web.1]: ^
2017-06-06T04:15:35.153007+00:00 app[web.1]:
2017-06-06T04:15:35.153008+00:00 app[web.1]: TypeError: The "digest" argument is required and must not be undefined
2017-06-06T04:15:35.153009+00:00 app[web.1]: at pbkdf2 (crypto.js:635:11)
2017-06-06T04:15:35.153010+00:00 app[web.1]: at Object.exports.pbkdf2Sync (crypto.js:628:10)
2017-06-06T04:15:35.153012+00:00 app[web.1]: at model. (/app/modules/users/server/models/user.server.model.js:112:26)
2017-06-06T04:15:35.153011+00:00 app[web.1]: at model.UserSchema.methods.hashPassword (/app/modules/users/server/models/user.server.model.js:123:19)
2017-06-06T04:15:35.153013+00:00 app[web.1]: at _next (/app/node_modules/hooks-fixed/hooks.js:62:30)
2017-06-06T04:15:35.153013+00:00 app[web.1]: at fnWrapper (/app/node_modules/hooks-fixed/hooks.js:186:8)
2017-06-06T04:15:35.153014+00:00 app[web.1]: at model. (/app/node_modules/mongoose/lib/plugins/saveSubdocs.js:20:7)
2017-06-06T04:15:35.153014+00:00 app[web.1]: at _next (/app/node_modules/hooks-fixed/hooks.js:62:30)
2017-06-06T04:15:35.153015+00:00 app[web.1]: at fnWrapper (/app/node_modules/hooks-fixed/hooks.js:186:8)
2017-06-06T04:15:35.153015+00:00 app[web.1]: at /app/node_modules/mongoose/lib/plugins/validateBeforeSave.js:33:13
2017-06-06T04:15:35.153016+00:00 app[web.1]: at /app/node_modules/kareem/index.js:131:16
2017-06-06T04:15:35.153016+00:00 app[web.1]: at _combinedTickCallback (internal/process/next_tick.js:95:7)
2017-06-06T04:15:35.153017+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:161:9)
2017-06-06T04:15:35.167579+00:00 app[web.1]: error: Forever detected script exited with code: 1
2017-06-06T04:15:35.173500+00:00 app[web.1]: error: Script restart attempt #1
2017-06-06T04:15:35.292903+00:00 app[web.1]:
2017-06-06T04:15:35.294191+00:00 app[web.1]:
2017-06-06T04:15:35.310954+00:00 app[web.1]: + Error: Certificate file or key file is missing, falling back to non-SSL mode
2017-06-06T04:15:35.311037+00:00 app[web.1]: To create them, simply run the following from your shell: sh ./scripts/generate-ssl-certs.sh
2017-06-06T04:15:35.311039+00:00 app[web.1]:
2017-06-06T04:15:35.916892+00:00 app[web.1]: Db.prototype.authenticate method will no longer be available in the next major release 3.x as MongoDB 3.6 will only allow auth against users in the admin db and will no longer allow multiple credentials on a socket. Please authenticate using MongoClient.connect with auth credentials.
I don't know what to do now because Heroku supports tell me thar the error is in my code but I haven't changed anything there!
CLI screenshot
Just had this problem. We were able to fix it by enforcing our preferred node version in package.json > engines.
We previously had it at
"node": ">=0.10.0"
We changed it to
"node": "6.6.0"
And then pushed that to Heroku, and that fixed the issue.
Not entirely sure what the problem is, but we found this link which lead us to believe the node version was the issue:
https://github.com/nodejs/node/wiki/Breaking-changes-between-v4-LTS-and-v6-LTS#crypto

Setting up Sentry in an Elixir app, getting undefined function String.trim/2

I'm following these instructions (https://github.com/getsentry/sentry-elixir) to set up Sentry error notifications in an Elixir/Phoenix app. It works fine in my dev environment, but when I push to production (using Heroku) I get the following error which seems to occur within the Sentry module itself: (UndefinedFunctionError) undefined function String.trim/2.
Here is the full log output:
** (exit) an exception was raised:
2016-12-01T23:14:00.741733+00:00 app[web.1]: ** (UndefinedFunctionError) undefined function String.trim/2
2016-12-01T23:14:00.741736+00:00 app[web.1]: (elixir) String.trim("** (Phoenix.ActionClauseError) bad request to MyApp.UserController.create, no matching action clause to process request", "*")
2016-12-01T23:14:00.741737+00:00 app[web.1]: (sentry) lib/sentry/event.ex:65: Sentry.Event.transform_exception/2
2016-12-01T23:14:00.741738+00:00 app[web.1]: (sentry) lib/sentry.ex:86: Sentry.capture_exception/2
2016-12-01T23:14:00.741739+00:00 app[web.1]: (plug) lib/plug/error_handler.ex:96: Plug.ErrorHandler.__catch__/5
2016-12-01T23:14:00.741740+00:00 app[web.1]: (my_app) lib/my_app/endpoint.ex:1: MyApp.Endpoint.phoenix_pipeline/1
2016-12-01T23:14:00.741741+00:00 app[web.1]: (my_app) lib/my_app/endpoint.ex:1: MyApp.Endpoint.call/2
2016-12-01T23:14:00.741742+00:00 app[web.1]: (plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
2016-12-01T23:14:00.741742+00:00 app[web.1]: (cowboy) src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4
and when I try to access alias String by logging into the iex via heroku run, I get nil.
Any idea why the String module is undefined in production only?
i think you need to force heroku to use elixir version 1.3.x
If you use the heroku-buildpack-elixir set your elixir version to minimum of 1.3.0
https://github.com/HashNuke/heroku-buildpack-elixir
There is the corresponding issue:
https://github.com/getsentry/sentry-elixir/issues/95

Deploying Play 2.0 app on Heroku

So I am kind of new to setting up servers. And I have been struggling with various sql issues all night. I think the only thing that sits between me and a successfully running play app is this: error
Starting process with command `target/start -Dhttp.port=80 `
2012-04-04T05:58:52+00:00 app[web.1]: Play server process ID is 1
2012-04-04T05:58:53+00:00 app[web.1]: [info] play - database [default] connected at jdbc:mysql://us-cdbr-east.cleardb.com/heroku_cd914b667dae168
2012-04-04T05:58:56+00:00 app[web.1]: [info] play - Application started (Prod)
2012-04-04T05:58:56+00:00 app[web.1]: Oops, cannot start the server.
2012-04-04T05:58:56+00:00 app[web.1]: org.jboss.netty.channel.ChannelException: Failed to bind to: /0.0.0.0:80
... more errors
Does anyone spot any problems? Do I need any java options arguments?
I tried specifying a user port in the Procfile, and got a different error message:
2012-04-04T07:01:36+00:00 heroku[web.1]: Starting process with command `target/start -Dhttp.port=2000`
2012-04-04T07:01:37+00:00 app[web.1]: Play server process ID is 1
2012-04-04T07:01:40+00:00 app[web.1]: [info] play - database [default] connected at jdbc:mysql://us-cdbr-east.cleardb.com/heroku_cd914b667dae168
2012-04-04T07:01:45+00:00 app[web.1]: [info] play - Application started (Prod)
2012-04-04T07:01:45+00:00 app[web.1]: [info] play - Listening for HTTP on port 2000...
2012-04-04T07:01:46+00:00 heroku[web.1]: Error R11 (Bad bind) -> Process bound to port 2000, should be 47248 (see environment variable PORT)
2012-04-04T07:01:46+00:00 heroku[web.1]: Stopping process with SIGKILL
2012-04-04T07:01:47+00:00 heroku[web.1]: Process exited with status 137
2012-04-04T07:01:47+00:00 heroku[web.1]: State changed from starting to crashed
I have no idea what is happening. How do I change this environment variable? This heroku process model is very confusing to me.
I think the problem is that you're not allowing Heroku to specify the port. Googling your error I find: https://devcenter.heroku.com/articles/error-codes#r11__bad_bind
So instead of doing this:
web: target/start -Dhttp.port=80
Do this
web: target/start -Dhttp.port=$PORT
James has a nice writeup on getting a more advanced Play 2.0 app deployed here.

Resources