I’m a bit new to this, but I followed the this Youtube tutorial on how to build a Slack Bot but I can’t seem to make it work.
Here is my code,
For index.js
require = require("esm")(module/*, options*/)
module.exports = require("./app.js")
For app.js
import { RTMClient } from "@slack/rtm-api";
import { SLACK_0AUTH_TOKEN } from './constants.js';
const rtm = new RTMClient(SLACK_0AUTH_TOKEN);
rtm.start().catch(console.error);
rtm.on('ready', async () => {
console.log('Bot is now online');
});
For package.json
{
"name": "slackapi",
"version": "1.0.0",
"description": "Slack Bot Testing",
"main": "src",
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"start": "node ."
},
"author": "",
"license": "ISC",
"dependencies": {
"@slack/rtm-api": "^7.0.0",
"@slack/web-api": "^7.3.1",
"esm": "^3.2.25"
}
}
I’ve found similar articles on using ES6 modules in Node12 but I am currently using Node Version18, and using import modules basically messes up some of my referencing.