AnomalyInnovations / serverless-bundle

Optimized packages for ES6 and TypeScript Node.js Lambda functions without any configuration.
https://serverless-stack.com/chapters/package-lambdas-with-serverless-bundle.html
MIT License
531 stars 153 forks source link

Problem when using package formidable / node-formidable or anything that includes it, webpack doesn't compile the package correctly #42

Open tcastelli opened 4 years ago

tcastelli commented 4 years ago

As you can see on this thread https://github.com/node-formidable/node-formidable/issues/337

node-formidable or other packages using it fail to compile correctly this line

if (global.GENTLY) require = GENTLY.hijack(require);

creating

var require;if (global.GENTLY) require = GENTLY.hijack(require);

this makes that later requires included are not properly transpiled and fail after deploy in the line var crypto = require("crypto")

the easiest workaround found in the thread is to add

plugins: [
     new webpack.DefinePlugin({ "global.GENTLY": false })
], 

but that doesn't seem to be possible with this plugin right now. Any chance to allow a new custom option "definitions" so this plugin uses defineplugin underneath to create them?

jayair commented 4 years ago

@tcastelli Hmm that's interesting. We don't have plans to add that option just yet. But from looking at that thread. Do you think they are going to address that issue soon?

tcastelli commented 4 years ago

No idea tbh, I just forked this project and added the missing plugin and all is working for now. It's a shame that there's no way to customize this plugin a little more. I guess this plugin could look for a json file path and add those external options to webpack easily.

jayair commented 4 years ago

Yeah I'll keep this open. If more people run into this or something similar we'll fix it.

rodrigogs commented 3 years ago

I have the same problem and I don't want to create a lambda layer just to have a single dependency working :/

jayair commented 3 years ago

We have a specific fix for Formidable — https://github.com/AnomalyInnovations/serverless-bundle#package-specific-config