I'v just deployed my api on my server, it worked great until i used the spread syntax. Which now gives me back this error :
(node:17373) UnhandledPromiseRejectionWarning: /home/admin/api/src/graphql/index.js:15
{ ...accChild, [currKey]: {
^^^
SyntaxError: Unexpected token ...
at new Script (vm.js:80:7)
at createScript (vm.js:274:10)
at Object.runInThisContext (vm.js:326:10)
at Module._compile (internal/modules/cjs/loader.js:664:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
(node:17373) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:17373) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Any ideas ?
So the code is working locally and this is the whole line :
let resolvers = resolversExport.reduce((acc, curr) => {
let currArray = require(`./resolvers/${curr}`);
return Object.keys(currArray).reduce((accChild, currKey) =>
{ ...accChild, [currKey]: {
...(accChild[currKey] || {}),
...currArray[currKey]}
},
acc);
}, {});
FIXED Look at the comments, {} must be wrapped around () in arrow functions. (i will delete this if someone wants to put it as an official answer)
let resolvers = resolversExport.reduce((acc, curr) => {
let currArray = require(`./resolvers/${curr}`);
return Object.keys(currArray).reduce((accChild, currKey) =>
({ ...accChild, [currKey]: {
...(accChild[currKey] || {}),
...currArray[currKey]})
},
acc);
}, {});