Closed RaminKav closed 1 year ago
Hey @RaminKav, did you solve this issue? I am getting something very similar when bundling with webpack.
@AdamDaviesAppex I got the same problem. It is caused by having two separate module instances of the @google-cloud/functions-framework
module. One is bundled with your code and one is run with the CLI command.
@google-cloud/functions-framework
uses a map variable to register the handler. In this case, the handler is registered with the bundled instance and the instance ran with the CLI returns undefined. One solution is to filter '@google-cloud/functions-framework' from bundling.
If you are using webpack, add these lines to your config file:
externalsType: 'commonjs',
externals: ['@google-cloud/functions-framework'],
@Aidiiin you just saved me from hours trying to make this thing work, thanks
I have a typescript project that has a couple cloudEvent functions. I want to test these functions with functions-framework.
They work in javascript using
tsc
, using the scriptFUNCTION_TARGET=test npx functions-framework --signature-type=cloudevent
However, when i try to bundle my project (which is necessary when i eventually need to deploy this to GCP, since it uses a lot of dependencies from other folders in my monorepo), i get the following error when running the above script:
looking through the bundled JS file, i can find the function is there. I suspect something with the imports of functions-framework might not be working/registering the cloudEvent properly in the bundled file?
Ive tried with both
esbuild
andvercel/ncc
Here is a snippet of the vercel/ncc bundle: