Hi,
When I try to use an Object spread operator inside a lambda function like this:
// tester.js
exports.handler = async function() {
const obj = { a: 'a', c: 'c' };
const obj2 = {
b: 'b',
...obj,
};
return {
statusCode: 200,
body: JSON.stringify(obj2),
};
};
After deploying it, when I try to invoke it thru /.netlify/functions/tester
I end up with the following error:
{
-
errorType: “Runtime.ImportModuleError”,
-
errorMessage: “Error: Cannot find module ‘/opt/build/repo/node_modules/@babel/runtime/helpers/objectSpread2’ Require stack: - /var/task/src/src/functions/tester.js - /var/task/tester.js - /var/runtime/UserFunction.js - /var/runtime/index.js”,
-
trace: [
-
“Runtime.ImportModuleError: Error: Cannot find module ‘/opt/build/repo/node_modules/@babel/runtime/helpers/objectSpread2’”,
-
“Require stack:”,
-
“- /var/task/src/src/functions/tester.js”,
-
“- /var/task/tester.js”,
-
“- /var/runtime/UserFunction.js”,
-
“- /var/runtime/index.js”,
-
" at _loadUserApp (/var/runtime/UserFunction.js:100:13)",
-
" at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)",
-
" at Object. (/var/runtime/index.js:43:30)",
-
" at Module._compile (internal/modules/cjs/loader.js:1015:30)",
-
" at Object.Module._extensions…js (internal/modules/cjs/loader.js:1035:10)",
-
" at Module.load (internal/modules/cjs/loader.js:879:32)",
-
" at Function.Module._load (internal/modules/cjs/loader.js:724:14)",
-
" at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)",
-
" at internal/main/run_main_module.js:17:47"]
-
}
Any idea how I can go around this issue while still be able to using the object spread operator?
Array spread operator seems fine tho, it’s just object spread operator than seems to be causing issues.