Skip to content
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

Throwing error in serverless function. #182

Closed
alxmhe opened this issue Sep 13, 2019 · 13 comments
Closed

Throwing error in serverless function. #182

alxmhe opened this issue Sep 13, 2019 · 13 comments

Comments

@alxmhe
Copy link

alxmhe commented Sep 13, 2019

? new require(opts.scheme).Agent({ keepAlive: true })

is attempting to require dynamically.
This seems to warn during build of a serverless function (tested with Netlify) :

WARNING in /node_modules/faunadb/src/Client.js 73:24-48
Critical dependency: the request of a dependency is an expression

and ultimately an error on execution :

Response with status 500 in 132 ms.
Error during invocation:  { Error: Cannot find module 'https'

Do I need a specific webpack configuration?

@dijonmusters
Copy link

I am experiencing the same issue when trying to initialise the client in a Netlify function.

// functions/test.js
require('dotenv').config();
const faunadb = require('faunadb');
const q = faunadb.query;

const client = new faunadb.Client({
  secret: process.env.FAUNADB_SECRET
});

exports.handler = function(event, context, callback) {
  callback(null, {
    statusCode: 200,
    body: "Hello, World"
  });
}
// webpack.functions.js
const webpack = require('webpack');

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

Running locally with netlify-lambda serve functions -c ./webpack.functions.js

// Error running locally
Error during invocation:  Error: Cannot find module 'https'
    at a (/Users/jon/repos/test-fauna-netlify/lambda/test.js:31:192106)
    at new m (/Users/jon/repos/test-fauna-netlify/lambda/test.js:19:7867)
    at Object.<anonymous> (/Users/jon/repos/test-fauna-netlify/lambda/test.js:19:6093)
    at a (/Users/jon/repos/test-fauna-netlify/lambda/test.js:1:158)
    at /Users/jon/repos/test-fauna-netlify/lambda/test.js:1:957
    at Object.<anonymous> (/Users/jon/repos/test-fauna-netlify/lambda/test.js:1:967)
    at Module._compile (internal/modules/cjs/loader.js:936:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
    at Module.load (internal/modules/cjs/loader.js:790:32)
    at Function.Module._load (internal/modules/cjs/loader.js:703:12)
    at Module.require (internal/modules/cjs/loader.js:830:19)
    at require (internal/modules/cjs/helpers.js:68:18)
    at /Users/jon/repos/test-fauna-netlify/node_modules/netlify-lambda/lib/serve.js:120:17
    at Layer.handle [as handle_request] (/Users/jon/repos/test-fauna-netlify/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/jon/repos/test-fauna-netlify/node_modules/express/lib/router/route.js:137:13)
    at next (/Users/jon/repos/test-fauna-netlify/node_modules/express/lib/router/route.js:131:14) {
  code: 'MODULE_NOT_FOUND'
}
// Error running deployed version on Netlify
{
  "errorMessage": "Cannot find module 'https'",
  "errorType": "Error",
  "stackTrace": [
    "new m (/var/task/test.js:19:7867)",
    "Object.<anonymous> (/var/task/test.js:19:6093)",
    "a (/var/task/test.js:1:220)",
    "/var/task/test.js:1:1019",
    "Object.<anonymous> (/var/task/test.js:1:1029)",
    "Module._compile (module.js:652:30)",
    "Object.Module._extensions..js (module.js:663:10)",
    "Module.load (module.js:565:32)",
    "tryModuleLoad (module.js:505:12)"
  ]
}

@WvanDam
Copy link

WvanDam commented Sep 14, 2019

Experiencing the same, with the same setup as @dijonmusters.

@WvanDam
Copy link

WvanDam commented Sep 14, 2019

This line was introduced in version 2.81. However, rolling back to version 2.8.0 did not fix the second issue, regarding the https module.

@WvanDam
Copy link

WvanDam commented Sep 14, 2019

2.7.0 appears to do the trick

@danieltodonnell
Copy link
Contributor

We're focussing on adding new drivers functionality and addressing the drivers issue people have been experiencing next week. If using the 2.7 fallback is difficult, it hopefully will only be for a short time.

Thank you for your patience.

@dijonmusters
Copy link

Thanks for looking into this so quickly @danieltodonnell

I can confirm that the rollback to 2.7.0 is working for me 🙂

@cryptiklemur
Copy link

cryptiklemur commented Sep 20, 2019

Can also replicate the https module error when using webpack targeting webworker (cloudflare workers)

@eigilsagafos
Copy link

@danieltodonnell Any news on this?

@danieltodonnell
Copy link
Contributor

danieltodonnell commented Oct 1, 2019

Yes! This has had all our minds on it for the past few days, and we have moved from an optional keep alive flag to a much more involved solution that we've been testing thoroughly. The good news is: we have developed a solution that we believe will solve this entirely.

It will be released in our v2.9 JS driver next week

@eigilsagafos
Copy link

Great! Thanks for the update @danieltodonnell

@danieltodonnell
Copy link
Contributor

For anyone blocked by this issue, I am pleased to report that you should now be UN-blocked as-of version [email protected]

https://www.npmjs.com/package/faunadb/v/2.9.2

This has been rigorously tested to have a smooth experience. If you experience any issues, feel free to tell us in Fauna Slack Community channel.

We apologize for the delay and inconvenience. Thank you for your patience.

@danieltodonnell
Copy link
Contributor

I'm closing this issue but let us know if there are further issues

@jaymakes11
Copy link

jaymakes11 commented Nov 28, 2019

I'm seeing the following error while trying to use the driver in a Cloudflare Worker:

ReferenceError: XMLHttpRequest is not defined

@aequasi Sounds like you're using Workers, are you seeing this issue?

I can open a new issue for this if that would be best.


EDIT: Opened #207 for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants