I ran into a problem while building a webpack.
Discord client is not initialized.
This is my first application on Electron. Help please.
Error: Uncaught TypeError: i (...). Client is not a constructor in webpack file.
I ask for help, I will be very glad for a good answer. Below I will provide the code of all files. this problem look like in browser
main.js
const path = require('path');
const url = require('url');
const {app,BrowserWindow} = require('electron');
const {sendMessage,isValidForm} = require('./back.js');
let win;
function createWindow() {
win = new BrowserWindow({
width: 1200,
height : 800,
icon : __dirname + "/img/icon.png"
});
win.loadURL(url.format({
pathname: path.join(__dirname,"/html/index.html"),
protocol: 'file:',
slashes: true
}));
win.webContents.openDevTools();
win.on('closed', () => {
win = null;
});
}
app.on('ready', createWindow);
app.on('window-all-closed',() => {
app.quit();
});
webpack.config.js
var path = require('path');
module.exports = {
entry: './src/components/main.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
externals: [
(function () {
var IGNORES = [
'electron',
'fs'
];
return function (context, request, callback) {
if (IGNORES.indexOf(request) >= 0) {
return callback(null, "require('" + request + "')");
}
return callback();
};
})()
]
};
back.js
const Discord = require('discord.js');
const bot = new Discord.Client();
bot.login("token")
function isValidForm (first,second) {
if(first.value == "" || second.value == "") {
return alert('Одна из форм не заполненна')
}
sendMessage(first.value, second.value);
}
function sendMessage (channelName,message) {
const channel = bot.channels.cache.find(ch => ch.name === channelName);
if(!channel) {
return alert("Канал с таним названием не найден!");
}
channel.send(message);
}
module.exports = {sendMessage,isValidForm};