I had an error with this code
exports.getResults = (req, res) => {
status = await miDealApi.getResults()
res.json({
status: status
})
}
The issue was that i used 'await' without declaring the method as 'async', but the error Node.js was giving me was very unclear, and didn't help me figuring it out at all.
internal/modules/cjs/loader.js:999
throw err;
^
[wrapSafe (internal/modules/cjs/loader.js:979:16),Module._compile
(internal/modules/cjs/loader.js:1027:27),Object.Module._extensions..js
(internal/modules/cjs/loader.js:1092:10),Module.load
(internal/modules/cjs/loader.js:928:32),Function.Module._load
(internal/modules/cjs/loader.js:769:14),Module.require
(internal/modules/cjs/loader.js:952:19),require
(internal/modules/cjs/helpers.js:88:18),Object.<anonymous> (C:\Users\user\Documents\DT\projects\suresort-manager\controllers\waveFactory.js:6:30),Module._compile
(internal/modules/cjs/loader.js:1063:30),Object.Module._extensions..js
(internal/modules/cjs/loader.js:1092:10)]
PS C:\Users\user\Documents\DT\projects\suresort-manager>
Is there anything i can do to make errors like this clearer in the future?
Uncaught SyntaxError: await is only valid in async function. The error chrome dev console gives me isUncaught SyntaxError: await is only valid in async functions and the top level bodies of modules. Your error is probably related to the exports module being malformed due to the async/await issue.awaitwithin needs to beasyncfunction