netlify / netlify-faunadb-example

Using FaunaDB with netlify functions
https://www.netlify.com/blog/2018/07/09/building-serverless-crud-apps-with-netlify-functions--faunadb/
385 stars 121 forks source link

Issue with formidable package inside of faunadb npm module #8

Open mrispoli24 opened 5 years ago

mrispoli24 commented 5 years ago

I found an issue when trying to run this where I receive the error:

WARNING in ../node_modules/formidable/lib/incoming_form.js 1:43-50
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

The fix for me was to add a webpack.functions.js file to the root with the following:

const webpack = require('webpack');

module.exports = {
  plugins: [ new webpack.DefinePlugin({ "global.GENTLY": false }) ]
};

In package.json the serve and build commands needed to add this per the documentation.

"dev:server": "netlify-lambda serve functions --config ./webpack.functions.js",
"netlify:build:lambda": "netlify-lambda build functions --config ./webpack.functions.js"

This allowed this to compile properly without the error. Not sure if something changed in the formidable package or if anyone else has come across this.

iamtekeste commented 5 years ago

@mrispoli24 Thank you so much for this! I was pulling my hair out for a couple of hours!!

codeth commented 4 years ago

@mrispoli24 Another grateful dev here, thank you for documenting this! Problem solved.

In my case it was the same issue with formidable, but from auth0 rather than faunadb.

I had been successfully using Netlify Dev to serve some self-contained functions locally (with no build steps) and had just set up netlify-lambda so that I could build them from TypeScript source files instead. On building, I got the following warning:

WARNING in ../node_modules/formidable/lib/incoming_form.js 1:43-50
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
 @ ../node_modules/formidable/lib/index.js
 @ ../node_modules/superagent/lib/node/index.js
 @ ../node_modules/rest-facade/src/Client.js
 @ ../node_modules/rest-facade/src/index.js
 @ ../node_modules/auth0/src/auth/index.js
 @ ../node_modules/auth0/src/index.js
 @ ./image-signature.ts

Using the application resulted in the same error TypeError: n is not a function as reported by others on https://github.com/netlify/netlify-lambda/issues/64.

byungjuJin commented 3 years ago

superagent need to upgrade formidable Please check out below

https://github.com/visionmedia/superagent/issues/1609 https://github.com/node-formidable/formidable/issues/337