module.exports is undefined
ebisbe opened this issue · 3 comments
Hello,
Yesterday I added this plugin to my project and everything broke up. I have finally manage to get it working by transpiling all modules to 'commonjs' with the .babelrc configuration. I think that some kind of explanation in the FAQ's would help to avoid this issue.
The first message I got in the Lambda invocations was:
callback called with Error argument, but there was a problem while retrieving one or more of its message, name, and stack
In the logs I could read without any luck:
module initialization error: TypeError
Finally executing the function locally I could see that the actual error was:
module.exports.testFn = epsagon.lambdaWrapper(handler.testFn);
^
TypeError: Cannot set property 'testFn' of undefined
With a fast Console log I found that module.exports was indeed 'undefined'. After reading a little I come to the conclusion that I need to add:
"modules": "commonjs"
to my .babelrc file as I was targeting node 8.10 with babel.
Hi @ebisbe, And thanks for the detailed explanation. Do you think there might be any better solution here so next developers won't even encounter this? or is this a thing for FAQ?
BTW - have you installed the epsagon library to your package.json? or just the plugin?
Hi @ranrib,
Yes, I got both installed. The plugin just does all the wrapping for the epsagon-node package as you know.
And yes there's indeed a solution I found but my knowledge on that matter is not so broad that I'm not sure what will be any side effects so I forgot to comment it in the post. . As I read throught several Stack overflow issues module.exports
is the same as exports
. And webpack/webpack#5977 there's this comment
You are inside of an EcmaScript module in which `module.exports` is undefined and readonly.
Check PR #35 for a proposal of changes.