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

Add Nodejs 12 runtime support #304

Closed
jaytula opened this issue Sep 21, 2020 · 3 comments
Closed

Add Nodejs 12 runtime support #304

jaytula opened this issue Sep 21, 2020 · 3 comments
Labels
type: feature code contributing to the implementation of a feature and/or user facing functionality

Comments

@jaytula
Copy link

jaytula commented Sep 21, 2020

Is your feature request related to a problem? Please describe.

I am trying to import the npm library simple-oauth2 and use it with a netlify function
and also use netlify-lambda to test locally.

import simpleOauth from 'simple-oauth2'

export const handler = (event: APIGatewayEvent) => {
  return {
    statusCode: 200,
    body: 'Hello!!!'
  }
}

I believe that since the library depends on private class properties which is supported in
Nodejs 12 runtime, it will not work with netlify-lambda that appears to run with nodejs 8 runtime
according to the README.

Describe the solution you'd like

A way to choose the nodejs runtime by setting the environment variable locally perhaps like:

https://www.netlify.com/blog/2019/12/04/node.js-12-now-available-for-netlify-functions/

Additional context

An error like this happens when trying to require simple-oauth2 and using netlify-lambda serve:

oauth-netlify-practice/node_modules/simple-oauth2/lib/client.js:19
  #config = null;
  ^

SyntaxError: Invalid or unexpected token
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (auth-netlify-practice/node_modules/simple-oauth2/index.js:3:16)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
@jaytula jaytula added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Sep 21, 2020
@erezrokah
Copy link
Contributor

Hi @jaytula, do you mind sharing a repo reproducing this issue? It will make it easier to debug.

@jaytula
Copy link
Author

jaytula commented Sep 28, 2020

@erezrokah Ok. Here is the repo:

https://github.com/jaytula/netlify-lambda-nodejs12-example

To reproduce the issue:

git clone https://github.com/jaytula/netlify-lambda-nodejs12-example
cd netlify-lambda-nodejs12-example
npm install
npm start

If you comment out the PROBLEM START to PROBLEM END in ./src/lambda/hello.ts, the http://localhost:9000/.netlify/functions/hello endpoint will work.

@erezrokah
Copy link
Contributor

This might be a Webpack issue webpack/webpack#10216

@danez danez closed this as completed Jul 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

No branches or pull requests

3 participants