I am running a lambda function with apollo-server-lambda, graphql, and typeorm.
Every function works fine in “netlify dev” and calls are made etc. No issues.
However, once I deploy to netlify it seems to remove the MySQL package that typeorm is reliant on as I am connecting to a MySQL database. (I have tried the serverless-typeorm and serverless-mysql packages too).
My file structure is:
built files from Server that graphql function points to (tried from netlify build and build and commit for netlify).
server.js - (This requires typeorm, MySQL, and other packages, other packages seem to work?)
PackageJson (I have tried including all deps here without the server packagejson too)
I have deployed to App ID: c8917f89-5771-44ae-88f0-c1ebda658dbb
on a branch deploy on branch newDb.
I will be willing to give access to the git repo that is private to netlify support team members.
I have tried to build functions with netlify-lambda, tried not building at all, etc.
As mentioned before it works in dev and netlify dev
Hi, update… So it seems to work when I set the branch to be the production target branch and deploy to production? However, when it is a preview branch the package is not installed / doesnt work?
I think if this is the case the issue needs to be looking into as it would mean all my preview deploys will not work?
Where are you setting the production branch so that things work? That makes me wonder if there’s an node_env setting somewhere that’s set to ‘development’ in every other case, so not installing your mysql package whenever you expect. Could that be possible?
I’m also seeing in the file structure you listed about that there’s a server directory. It seems like you may already know this and have gotten your app running in some cases, but just in case: on Netlify, there’s no server at runtime, so you won’t be able to run a database on Netlify:
Thank you for the reply, I actually forgot to update the post. I did solve this by trial and error. I ended up requiring the MySQL package in every single function file and then it worked. Removed one by one until found the file it needed to be in, however, when running netlify dev it seemed to work from another file which still baffled me. However, now it is working!
Sorry to not update and waste your time replying, however if anyone else has this issue, I recommend having a functions own node_modules and requiring in each function file to find out which one needs it haha