I'm trying to set up my nodejs backend functions to use Auth0 for IAM services.
I can successfully deploy functions to my IBM Cloud account that don't uses auth0 library, but if I try to upload a function that uses auth0 library I receive the following error:
error: Unable to create action 'function_name': The request content was malformed: Unexpected end-of-input at input index 1394034 (line 1, position 1394035), expected '"':
I've tried to use externals in my webpack.config.js file:
// webpack.config.js
externals: {
auth0: "commonjs auth0"
}
// mycode.js
const ManagementClient = require('auth0').ManagementClient;
and I can successfully deploy the function but when I call the endpoint I receive this error:
(0 , r(...).ManagementClient) is not a constructor
- I'm using webpack v5.0.0 and tried also with v4.x.x
- Auth0 library: https://github.com/auth0/node-auth0
I found this article: Adding extra npm modules to IBM Cloud Functions with Docker
Basically if I understand your question right, you need an additional package that is not included in the IBM Cloud Functions base image. The packages that are included by default are listed here. But auth0 is not part of the list.
So following the blog post, you can create a Dockerfile.
Build the image (assuming you have a docker build environment and a working Docker account) and push it to Dockerhub:
Now you can create a source.js file containing
and the rest of your code.
I hope this works for you. I have corrected some typos in this post and tested it. It worked so far that I was able to use the auth0 module in the action code.