[solved] 502 Bad Gateway from Netlify on graphql

I’m Stumped !! Chrome and Safari showing the same results…

I’m getting 502’s whenever my code makes a graphql request

The auth requests (I’m using dbAuth over mySQL at Railway) are working fine

Everything runs locally, this is after a deploy that I hit the problem

Locally I can see everything – in prod on Netlify, only scaffolded dbAuth pages are working

I get Netlify log lines for the Auth function, but the Graphql function log never shows anything at all

It’s strange - this a project scaffolded up in the last month and it’s getting regular yarn rw upgrades

The dbAuth function is doing it’s thing and using the database just fine, I can signUp/login/logout/resetPW

redwood.toml

# This file contains the configuration settings for your Redwood app.
# This file is also what makes your Redwood app a Redwood app.
# If you remove it and try to run `yarn rw dev`, you'll get an error.
#
# For the full list of options, see the "App Configuration: redwood.toml" doc:
# https://redwoodjs.com/docs/app-configuration-redwood-toml

[web]
  title = "Redwood App"
  port = 8910
  apiUrl = "/.netlify/functions"
  includeEnvironmentVariables = [
    # Add any ENV vars that should be available to the web side to this array
    # See https://redwoodjs.com/docs/environment-variables#web
    'APRYSE_KEY'
  ]
[api]
  port = 8911
[browser]
  open = true
[notifications]
  versionUpdates = ["latest"]

netlify.toml

[build]
  command = "yarn rw deploy netlify"
  publish = "web/dist"
  functions = "api/dist/functions"

[dev]
  # To use [Netlify Dev](https://www.netlify.com/products/dev/),
  # install netlify-cli from https://docs.netlify.com/cli/get-started/#installation
  # and then use netlify link https://docs.netlify.com/cli/get-started/#link-and-unlink-sites
  # to connect your local project to a site already on Netlify
  # then run netlify dev and our app will be accessible on the port specified below
  framework = "redwoodjs"
  # Set targetPort to the [web] side port as defined in redwood.toml
  targetPort = 8910
  # Point your browser to this port to access your RedwoodJS app
  port = 8888

[[redirects]]
  from = "/*"
  to = "/200.html"
  status = 200

There are my 3 package.json files

When I run the project locally in dev the logs show

I can’t find __REDWOOD__AUTH_GET_CURRENT_USER in the codebase

???


api | 13:52:50 🌲 request completed 711ms
api | 13:52:50 🌲 incoming request POST xxx /graphql
api | 13:52:50 🐛 Parsing request to extract GraphQL parameters
api | 13:52:50 🐛 Processing GraphQL Parameters
api | 13:52:50 🐛 graphql-server GraphQL execution started: __REDWOOD__AUTH_GET_CURRENT_USER
api | 13:52:50 🌲 request completed 186ms
api | 13:52:50 🐛 graphql-server GraphQL execution completed: __REDWOOD__AUTH_GET_CURRENT_USER
api | 13:52:50 🐛 Processing GraphQL Parameters done.
api | 18:36:49 🌲 incoming request GET xxx /auth?method=getToken
api | 18:36:50 🌲 request completed 990ms
api | 18:36:50 🌲 incoming request POST xxx /graphql
api | 18:36:50 🐛 Parsing request to extract GraphQL parameters
api | 18:36:50 🐛 Processing GraphQL Parameters
api | 18:36:50 🐛 graphql-server GraphQL execution started: __REDWOOD__AUTH_GET_CURRENT_USER
api | 18:36:50 🌲 request completed 178ms
api | 18:36:50 🐛 graphql-server GraphQL execution completed: __REDWOOD__AUTH_GET_CURRENT_USER
api | 18:36:50 🐛 Processing GraphQL Parameters done.
api | 20:04:24 🌲 incoming request GET xxx /auth?method=getToken
api | 20:04:25 🌲 request completed 653ms
api | 20:04:25 🌲 incoming request POST xxx /graphql
api | 20:04:25 🐛 Parsing request to extract GraphQL parameters
api | 20:04:25 🐛 Processing GraphQL Parameters
api | 20:04:25 🐛 graphql-server GraphQL execution started: __REDWOOD__AUTH_GET_CURRENT_USER
api | 20:04:25 🌲 request completed 179ms
api | 20:04:25 🐛 graphql-server GraphQL execution completed: __REDWOOD__AUTH_GET_CURRENT_USER
api | 20:04:25 🐛 Processing GraphQL Parameters done.
api | 20:19:03 🌲 incoming request GET xxx /auth?method=getToken
api | 20:19:03 🌲 request completed 647ms
api | 20:19:03 🌲 incoming request POST xxx /graphql
api | 20:19:03 🐛 Parsing request to extract GraphQL parameters
api | 20:19:03 🐛 Processing GraphQL Parameters
api | 20:19:04 🐛 graphql-server GraphQL execution started: __REDWOOD__AUTH_GET_CURRENT_USER
api | 20:19:04 🌲 request completed 175ms
api | 20:19:04 🐛 graphql-server GraphQL execution completed: __REDWOOD__AUTH_GET_CURRENT_USER
api | 20:19:04 🐛 Processing GraphQL Parameters done.
api | 20:31:50 🌲 incoming request GET xxx /auth?method=getToken

Wo-Ho !! Netlify finally logged something (I left the log tab open since the problem)

Jan 8, 07:15:57 PM: Unknown application error occurred
Runtime.ImportModuleError

Jan 8, 07:15:57 PM: 249e02e7 Duration: 2075.07 ms	Memory Usage: 71 MB	

Jan 8, 07:15:57 PM: INIT_START Runtime Version: nodejs:18.v18	Runtime Version ARN: arn:aws:lambda:us-east-2::runtime:d949ec0248c1b8fbc8cbc6df1c986e05fb933506b51d53be82d46f9a37125bea

Jan 8, 07:15:58 PM: 2024-01-09T00:15:58.381Z	undefined	ERROR	Uncaught Exception 	{"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'xhr2'\nRequire stack:\n- /var/task/node_modules/@pdftron/pdfnet-node/lib/pdfnet.js\n- /var/task/api/dist/lib/pdf-net/docx-form-pdf.js\n- /var/task/api/dist/services/convertWordToPdfs/convertWordToPdfs.js\n- /var/task/api/dist/functions/graphql.js\n- /var/task/graphql.js\n- /var/runtime/index.mjs","stack":["Runtime.ImportModuleError: Error: Cannot find module 'xhr2'","Require stack:","- /var/task/node_modules/@pdftron/pdfnet-node/lib/pdfnet.js","- /var/task/api/dist/lib/pdf-net/docx-form-pdf.js","- /var/task/api/dist/services/convertWordToPdfs/convertWordToPdfs.js","- /var/task/api/dist/functions/graphql.js","- /var/task/graphql.js","- /var/runtime/index.mjs","    at _loadUserApp (file:///var/runtime/index.mjs:1087:17)","    at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)","    at async start (file:///var/runtime/index.mjs:1282:23)","    at async file:///var/runtime/index.mjs:1288:1"]}

Jan 8, 07:15:58 PM: INIT_REPORT Init Duration: 1163.09 ms	Phase: init	Status: error	Error Type: Runtime.ExitError

Jan 8, 07:57:45 PM: INIT_START Runtime Version: nodejs:18.v18	Runtime Version ARN: arn:aws:lambda:us-east-2::runtime:d949ec0248c1b8fbc8cbc6df1c986e05fb933506b51d53be82d46f9a37125bea

Jan 8, 07:57:46 PM: 2024-01-09T00:57:46.767Z	undefined	ERROR	Uncaught Exception 	{"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'xhr2'\nRequire stack:\n- /var/task/node_modules/@pdftron/pdfnet-node/lib/pdfnet.js\n- /var/task/api/dist/lib/pdf-net/docx-form-pdf.js\n- /var/task/api/dist/services/convertWordToPdfs/convertWordToPdfs.js\n- /var/task/api/dist/functions/graphql.js\n- /var/task/graphql.js\n- /var/runtime/index.mjs","stack":["Runtime.ImportModuleError: Error: Cannot find module 'xhr2'","Require stack:","- /var/task/node_modules/@pdftron/pdfnet-node/lib/pdfnet.js","- /var/task/api/dist/lib/pdf-net/docx-form-pdf.js","- /var/task/api/dist/services/convertWordToPdfs/convertWordToPdfs.js","- /var/task/api/dist/functions/graphql.js","- /var/task/graphql.js","- /var/runtime/index.mjs","    at _loadUserApp (file:///var/runtime/index.mjs:1087:17)","    at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)","    at async start (file:///var/runtime/index.mjs:1282:23)","    at async file:///var/runtime/index.mjs:1288:1"]}

Jan 8, 07:57:46 PM: INIT_REPORT Init Duration: 1535.12 ms	Phase: init	Status: error	Error Type: Runtime.ExitError

Jan 8, 07:57:49 PM: 2024-01-09T00:57:49.044Z	undefined	ERROR	Uncaught Exception 	{"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'xhr2'\nRequire stack:\n- /var/task/node_modules/@pdftron/pdfnet-node/lib/pdfnet.js\n- /var/task/api/dist/lib/pdf-net/docx-form-pdf.js\n- /var/task/api/dist/services/convertWordToPdfs/convertWordToPdfs.js\n- /var/task/api/dist/functions/graphql.js\n- /var/task/graphql.js\n- /var/runtime/index.mjs","stack":["Runtime.ImportModuleError: Error: Cannot find module 'xhr2'","Require stack:","- /var/task/node_modules/@pdftron/pdfnet-node/lib/pdfnet.js","- /var/task/api/dist/lib/pdf-net/docx-form-pdf.js","- /var/task/api/dist/services/convertWordToPdfs/convertWordToPdfs.js","- /var/task/api/dist/functions/graphql.js","- /var/task/graphql.js","- /var/runtime/index.mjs","    at _loadUserApp (file:///var/runtime/index.mjs:1087:17)","    at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)","    at async start (file:///var/runtime/index.mjs:1282:23)","    at async file:///var/runtime/index.mjs:1288:1"]}

Jan 8, 07:57:49 PM: INIT_REPORT Init Duration: 2422.59 ms	Phase: invoke	Status: error	Error Type: Runtime.ExitError

This looks to be a problem with a 3rd party library…

I got rid of the alien_technology and everything’s working again

I’ll filter it in slowly if at all next time – that part wasn’t being used anymore anyway - pdftron will best used within the UI via a config file for me - note pdftron is now apryse

Thanks all who viewed !

Al;

p.s. I did install xhr, it didn’t help (I think…)

@ajoslin103 I’m not familiar with pdftron but it could be that that sdk to do document processing requires file system access (write access) and Netlify is an ephemeral file system — no write access via functions.

1 Like

I believe you are correct – that was what I was doing with that code

it can run elsewhere

thanks!!

Al;