Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

App Engine Standard project fails at runtime with: Error: Cannot find module 'mysql2/promise'

I have an app engine Node/Express/Typescript project that has been running fine for several years.

Today I deployed a new version. Everything in the build log looks good. However when the node server is started it fails

"Error: Cannot find module 'mysql2/promise'"

This is bizarre since the exact same code works fine locally AND the typescript build has no problem finding the module. (Not to mention that the module has been used by the project for several years!)

I could use some ideas about how to track this down since I'm out of ideas.

 

Solved Solved
0 3 1,275
1 ACCEPTED SOLUTION

So, I finally figured out what was happening

The mysql2 package got accidentally moved from dependencies to devDependencies in package.json.

The weird thing is that it happened 11 months ago. I've deployed many times since then with no problems. Not sure how that's possible.

View solution in original post

3 REPLIES 3

What scripts do you have in your package.json file?

Also note that the closest you can get to replicating GAE locally is by running an App with dev_appserver.py (see documentation). Unfortunately, this isn't supported for NodeJs (it's supported for Go 1.12+, Java 11/17, PHP 7/8, and Python 3 runtimes). This means that an App which runs successfully on local with say 'npm start' might not necessarily work on Production

 

..... NoCommandLine ......
 https://nocommandline.com
A GUI for Google App Engine

So, I finally figured out what was happening

The mysql2 package got accidentally moved from dependencies to devDependencies in package.json.

The weird thing is that it happened 11 months ago. I've deployed many times since then with no problems. Not sure how that's possible.

i interseted gogole cloud