I am creating an app for Freshdesk (FDK v 8.6.7, nodejs v14.*) and am trying to install and test Axios for use in server.js.
I am using the require command as expected within server.js…
const axios = require('axios');
On testing locally using fdk run I am getting this error when I run my axios.post() command. Specifically, I am firing it on the OnAppInstall, OnAppUpdate and OnAppUninstall events.
Note that it is looking for node_modules inside the server directory. But when I install it, it of course goes under the root directory, as expected. I tried using cd server to install it down there, but the axios directory always appears under the root’s node_modules.
I added an empty package.json file under /server and that helped in the install, but now I get the error
Exception occured while validation: Error while parsing file containing serverless functions. Please use the exports section as recommended in the Serverless Apps section of the SDK documentation.
…which is irritating, as this NOT a serverless app.
First, the axios package dependency: To add an npm package as a dependency for your app, you will need to add it to the "dependencies" key in manifest.json:
You will see this error if you are not using an exports block in your server/server.js file to export all the serverless functions and event handlers. Named exports don’t work.
For example, in server/server.js:
exports = {
onTicketCreateHandler: async function (payload) {
// ...
},
onTicketUpdateHandler: async function (payload) {
// ...
},
}
I’m still confused by this statement, though. If you are listening to product events in server.js, then, according to fdk (and us), your app uses serverless.
It’s also mentioned in the Installing section of the Axios documentation in NPM.
Our Freshworks CLI (fdk) uses the require() statement for importing the dependencies, and it doesn’t work with ES modules exported in the case of Axios.