Closed neeraj87 closed 1 year ago
Hi @neeraj87 - thanks for raising this
It's hard to tell from the stacktrace you've shared and I'm not familiar with how lambda supports ESM.
You could try commonjs (require('auth0')
), esModuleInterop or import * as auth0 from 'auth0'
If you can provide a repo that demonstrates the issue I could debug it for you.
the problem is webpack finds the module .mjs file and tries to load that.
this is the actual error:
https://github.com/auth0/node-auth0/issues/783#issuecomment-1500973549
this seems to be the fix:
https://github.com/auth0/node-auth0/issues/783#issuecomment-1501110011
@mribichich so the solution is to add .js
to my auth0 import?
when I do this > import * as auth0 from 'auth0.js';
it gives me the following error
Cannot find module 'auth0.js' or its corresponding type declarations.
@adamjmcgrath I tried using both import * as auth0 from 'auth0'
and import auth0 = require('auth0');
but its still not working.
For more clarity I am using serverless-bundle
for pack
@neeraj87 is your project in ESM? eg in package.json
you have "type": "module"
? also what moduleResolution
are you uisng?
I wasn't able to fix it, so went out to use axios with the api definitions... I kept getting other module import errors
đź‘‹ Have got a branch that should fix this here https://github.com/auth0/node-auth0/tree/fix-esm
Have tested it on serverless-bundle's Serverless Node.js Starter
You can see the modifications I had to do to get the serverless-bundle application to work with node-auth0
here https://github.com/AnomalyInnovations/serverless-nodejs-starter/compare/master...adamjmcgrath:serverless-nodejs-starter:master
npm i https://github.com/auth0/node-auth0/tree/fix-esm
Could someone test out the branch and let me know if ti works for them? Then I'll go ahead and ship a patch
Hey, is there a way I can npm install it? or do I just have to clone and link the branch?
Hi @PSoltes
Yes, either:
npm i https://github.com/auth0/node-auth0/tree/fix-esm
"auth0": "github:auth0/node-auth0#fix-esm"
to your package dependencies and run npm i
Tested with serverless-webpack
deployed via seed using esbuild-loader
and typescript. Works fine. Related webpack config:
externals: {
...(config.externals || {}),
formidable: "formidable",
},
resolve: {
...
alias: {
"superagent-proxy": false,
},
},
output: {
path: path.join(__dirname, ".webpack"),
library: {
type: "module",
},
},
experiments: {
outputModule: true,
},
Thanks @PSoltes - I'll raise a PR
@adamjmcgrath so do I just reinstall auth0 and will it start working?
@adamjmcgrath I updated auth0 and @types/auth0 package on my project but I still keep getting this error
2023-05-17T10:16:31.760Z undefined ERROR Uncaught Exception {
"errorType": "TypeError",
"errorMessage": "M is not a function",
"stack": [
"TypeError: M is not a function",
" at Object.91738 (/var/task/src/auth-lambda.js:540:5226)",
" at __webpack_require__ (/var/task/src/auth-lambda.js:3143:2090854)",
" at Object.59458 (/var/task/src/auth-lambda.js:540:15606)",
" at __webpack_require__ (/var/task/src/auth-lambda.js:3143:2090854)",
" at Object.16135 (/var/task/src/auth-lambda.js:2839:1079)",
" at __webpack_require__ (/var/task/src/auth-lambda.js:3143:2090854)",
" at Object.81557 (/var/task/src/auth-lambda.js:2726:36831)",
" at __webpack_require__ (/var/task/src/auth-lambda.js:3143:2090854)",
" at Object.96781 (/var/task/src/auth-lambda.js:2726:41526)",
" at __webpack_require__ (/var/task/src/auth-lambda.js:3143:2090854)"
]
}
I am trying to initialize Auth0 ManagementClient in my Lambda function (Node.js + Typescript)
and it gives me the following error
I am using the following versions for auth0
auth0: 3.3.0
and@types/auth0: 2.35.9
I am not sure what I am doing wrong here.