I'm trying to set up CloudCode on my app that uses Parse to be able to post to social media platforms using Ayrshare. I have gone through their setup, got my API key, and trying to follow instructions for installing the required NPM on Back4App, but it appears that I'm having issues installing the NPM 'social-post-api' on Back4App for my app, as running this job instantly fails. Error below my code and info. Ever since I set up the job, there are times where in dashboard ALL the CloudCode jobs disappear, so I'm really not sure what is going on here.
Parse Version: 2.8.4
under CloudCode package.json I have this:
{
"dependencies": {
"axios": "^0.24.0",
"jsdom": "^17.0.0",
"parse-html": "^1.3.2",
"social-post-api": "*",
"moment-timezone": "^0.5.32"
}
}
According to Back4App's article and video for adding an NPM, that is all I should have to do.
Within the main.js I have the following (there are other non-related jobs that have worked fine for well over a year, so I excluded those, just know there are other jobs):
const SocialPost = require('social-post-api');
Parse.Cloud.job('postToSocialMediaJob', async (request) => {
const { params, job } = request;
// Live API Key
const social = new SocialPost("MYKEYISHERE"); // Replace with your Ayrshare API key
try {
const postResponse = await social.post({
"post": "Today is a great day!",
"platforms": ["facebook"],
"mediaUrls": ["https://img.ayrshare.com/012/gb.jpg"],
});
if (postResponse) {
job.success(`Job completed successfully: ${JSON.stringify(postResponse)}`);
} else {
job.error("No response data from Ayrshare API");
}
} catch(error) {
console.log(error);
job.error(`Job failed due to error: ${error.message}`);
}
});
When I tap Run Now, it instantly fails and the only thing I get is this:
2024-01-31T21:24:45.093Z -
Error loading your cloud code:
Error: Cannot find module 'social-post-api'
Require stack:
- /usr/src/app/data/cloud/main.js
- /usr/src/app/cloudCodeWrapper.js
- /usr/src/app/node_modules/parse-server/lib/ParseServer.js
- /usr/src/app/node_modules/parse-server/lib/index.js
- /usr/src/app/src/back/app.js
- /usr/src/app/src/back/server.js
- /usr/src/app/src/back/index.js
- /usr/src/app/index.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/usr/src/app/data/cloud/main.js:5:20)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
It seems that you are trying to install a version of the "parse-html" module that does not exist.
Please, check the available versions here: https://www.npmjs.com/package/parse-html?activeTab=versions