-
Notifications
You must be signed in to change notification settings - Fork 12
Webpack not working correctly with crypto module #435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thank you for reporting the issue. This seems like either a webpack configuration issue or an unexpected difference between your local test environment with Node 20 and the remote runtime environment. I created PR #436 to make this easier to troubleshoot. This will report the underlying error caused by -Jonathan |
Hey @hessjcg , Thanks for taking the time! Even though the change above doesn't really catch the error itself I did put a breakpoint in to see if there is anything useful we can get out and this is what I found: I get: message is: stack:
So this is going to be a bundling / webpack issue: We're most likely bundling code that uses dynamic import() in a CJS context, and Node doesn't know how to deal with it at runtime. What's interesting is that I if I exclude it from the bundler it still hits the same error:
|
Hi @benedekdaniel, It sounds like this is a webpack issue. Unfortunately, this is beyond our area of expertise. If you find a solution that requires a change to this repo's code, let us know. |
We are trying to migrate to the official @google-cloud/cloud-sql-connector package in a Node.js backend (and test locally on Node 20), but we’re encountering the following error when calling connector.getOptions(...):
Support to node crypto module is required
After digging into the source, we traced this error to the node-crypto.ts module in the connector:
We verified that require("crypto") and require("crypto").webcrypto.subtle both work fine in our runtime.
However, calling getOptions(...) fails immediately, which means the issue is triggered during dynamic import of node:crypto.
Example:
The logs do show an available crpyto object and connector loaded from:
@google-cloud/cloud-sql-connector
Stacktrace
our webpack config:
webpack api config js
Webpack api dev config js
I've tried:
my-project:europe-west1:db-name
How to Reproduce
Use the latest version of @google-cloud/cloud-sql-connector (1.7.0)
Bundle your Node.js app using Webpack (target: "node", externals include webpack-node-externals)
Call await connector.getOptions(...) as shown above
Observe runtime error: Support to node crypto module is required
Environment details
OS: macOS Sequoia 15.3 (24D60)
Node.js version: v20.9.0
npm version: 10.8.2
@google-cloud/cloud-sql-connector: 1.7.0
Bundler: Webpack 5 (5.93.0) with webpack-node-externals, target: "node"
Transpiler: SWC
Other tooling: nodemon, source-map-support, v8-compile-cache
The text was updated successfully, but these errors were encountered: