node-mysql2: f.ClientHandshake is not a constructor

Hi,

When I use the package locally, everything works fine. However, when I use it inside an AWS Lambda function to connect to an RDS instance, I get this cryptic error:

TypeError: f.ClientHandshake is not a constructor
at new g (/var/task/index.js:275:62824)
at new o (/var/task/index.js:275:224046)
at e.exports.getConnection (/var/task/index.js:275:218705)
at e.exports.execute (/var/task/index.js:275:220197)
at /var/task/index.js:275:372341
at new Promise (<anonymous>)
at c.execute (/var/task/index.js:275:372308)
at /var/task/index.js:357:14189
at E (/var/task/index.js:316:24416)
at Generator._invoke (/var/task/index.js:316:24204)

Any idea what the issue is? I’m confident that the roles/security groups are all configured correctly.

Thanks

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 16 (10 by maintainers)

Most upvoted comments

Hi @sidorares Unfortunately, I lost a day facing the same issue, but not with AWS. Thanks to https://stackoverflow.com/questions/53524510/mysql2-typeerror-f-clienthandshake-is-not-a-constructor, I finally understood the problem was coming with Webpack as I use typescript.

However, why is this ticket closed? There is still an issue, because as soon as you minify the code for production, your module doesn’t work any more.

Please consider this issue (it might maybe only concern users using Typescript, but still, it’s an issue)

Thank you in advance

Yes, I’m using Webpack to bundle it. I did just notice I get a warning during the packaging stage that may be related

WARNING in ./node_modules/mysql2/lib/helpers.js
Module not found: Error: Can't resolve 'cardinal' in '<...>/node_modules/mysql2/lib'
 @ ./node_modules/mysql2/lib/helpers.js
 @ ./node_modules/mysql2/lib/parsers/binary_parser.js
 @ ./node_modules/mysql2/lib/commands/execute.js
 @ ./node_modules/mysql2/lib/commands sync ^\.\/.*\.js$
 @ ./node_modules/mysql2/lib/commands/index.js
 @ ./node_modules/mysql2/lib/connection.js
 @ ./node_modules/mysql2/index.js
 @ ./node_modules/mysql2/promise.js
 @ ./src/db/index.js
 @ ./src/db/models/<...>.js
 @ ./src/<...>.js
 @ ./src/<...>/index.js
 @ multi ./src/<...>/index.js

Hey @sidorares thanks for your answer. I just found out what was the problem: I was actually using netlify lambda (https://www.npmjs.com/package/netlify-lambda) to write a lambda function where I needed the mysql. This all resides within a project where I have nuxt and a webpack config.

What I did not realize was: The netlify lambda uses it’s own webpack config to build and serve my node function. So I was always adding the config stuff into the wrong webpack config. Now that I added it at the right place it worked. 🙈 thanks for your answer anyway!