Deployment without a manually uploaded node module folder didn't work

SSharp3/7/2023
As the title suggests, I had a really simple script that I needed to deploy and without my node modules folder manually uploaded (note, there was a package.json and all that), I couldn't properly deploy the script and was getting undefined errors from my dependancies.
SSharp3/7/2023
e629e6f4-8257-472b-8ef9-34809b5acd29
Bbrody3/7/2023
finally
SSharp3/7/2023
:monkey1:
SSharp3/7/2023
🤐
Bbrody3/7/2023
working on something right now, ill be back soon
Bbrody3/7/2023
in the meantime, screenshots please
SSharp3/7/2023
Ready!
Balance is satisfactory, currently 0.469175743382926796 ETH.
/app/index.js:50
channel.send({
^
TypeError: Cannot read properties of undefined (reading 'send')
at /app/index.js:50:13
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Node.js v18.12.1
SSharp3/7/2023
/// Dependancies ///
const { ethers } = require('ethers');
const { Client, GatewayIntentBits, EmbedBuilder } = require('discord.js');

/// Discord Token ///
const discordToken =
    'XXX';

/// Create a new client instance ///
const client = new Client({ intents: [GatewayIntentBits.Guilds] });

/// When the client is ready, run this code (only once) ///
client.once('ready', () => {
    console.log('Ready!');
});

/// Ethers Alchemy Provider ///
const provider = new ethers.AlchemyProvider(
    'homestead',
    'XXX'
);

const getBalance = async () => {
    provider
        .getBalance('
xxx')
        .then((balance) => {
            let ethBalance = ethers.formatEther(balance);
            const channel = client.channels.cache.get('XXX');
            if (ethBalance < 0.1) {
                let warningEmbed = new EmbedBuilder()
                    .setColor(0xff0000)
                    .setTitle('Balance Warning! Top up ASAP!')
                    .setDescription(`Current Balance: ${ethBalance} ETH`);

                console.log(
                    `WARNING: Balance is under 0.15 (${ethBalance} ETH), top up ASAP! Sending alert...`
                );
                channel.send({
                    content: 'XXX',
                    embeds: [warningEmbed],
                });
            } else {
                let standardEmbed = new EmbedBuilder()
                    .setColor(0x00ff00)
                    .setTitle('Balance Check')
                    .setDescription(`Current Balance: ${ethBalance}`);

                console.log(`Balance is satisfactory, currently ${ethBalance} ETH.`);

                channel.send({
                    embeds: [standardEmbed],
                });
            }
        });
};

/// Initialize Watcher ///
const startWatcher = async () => {
    await client.login(discordToken);
    getBalance();
    let getBalanceInterval = setInterval(getBalance, 21600000);
};

startWatcher();
SSharp3/7/2023
SSharp3/7/2023
SSharp3/7/2023
There we go, ofc just lmk if I'm missing anything
SSharp3/7/2023
take your time, no rush at all, apologies for the wait haha
Bbrody3/7/2023
obligatory question, have you modified anything in your local node_modules folder?
Bbrody3/7/2023
also, callback hell
Bbrody3/7/2023
async but no await
SSharp3/7/2023
no sir, never
Bbrody3/7/2023
can i see a screenshot of the variables tab in the service
SSharp3/7/2023
just node v18
SSharp3/7/2023
Bbrody3/7/2023
okay i was hoping so
SSharp3/7/2023
yep, always
SSharp3/7/2023
:aPES_Shake:
Bbrody3/7/2023
little side track though, im seeing a few 'XXX' meaning you stored secrets as plain text in your code?
SSharp3/7/2023
yeah, this is a one-off discord bot for a super small function
SSharp3/7/2023
someone could get hold of that secret and it really wouldnt matter haha
Bbrody3/7/2023
still though, please use service variables going forward, its just good practice
SSharp3/7/2023
service variables?
Bbrody3/7/2023
Bbrody3/7/2023
like that
Bbrody3/7/2023
but for your discord token
SSharp3/7/2023
shit, railway keeps getting better, ill be sure to peep docs for how that works and get on it immediately, thanks dude!
Bbrody3/7/2023
add a variable in there then access it with process.env.<variable name>
SSharp3/7/2023
you're the best
Bbrody3/7/2023
okay but thats not your issue
SSharp3/7/2023
i have many
SSharp3/7/2023
glad we could fix one
Bbrody3/7/2023
now back on track, locally, delete the node_modules folder then run npm i and tell me if your code still works
SSharp3/7/2023
worked
SSharp3/7/2023
side note
SSharp3/7/2023
ill work on callback hell later :PepeNervSmile:
Bbrody3/7/2023
its just const balance = await provider.getBalance('xxx');
SSharp3/7/2023
const getBalance = async () => {
    const initBalance = await provider.getBalance('XXX')
            let ethBalance = ethers.formatEther(initBalance);
SSharp3/7/2023
is that less hellish
SSharp3/7/2023
lol
SSharp3/7/2023
sorry, i swear i didnt open this for JS lessons :KEKW:
Bbrody3/7/2023
ethBalance can be a const
SSharp3/7/2023
done
SSharp3/7/2023
ty sensei
Bbrody3/7/2023
is client.channels.cache.get a promise?
SSharp3/7/2023
dont believe so
SSharp3/7/2023
would be if it was without cache
SSharp3/7/2023
actually i may be confusing versions of discord.js
SSharp3/7/2023
forget that
Bbrody3/7/2023
okay so at this point im just googleing for the error, so will you take over that for now
SSharp3/7/2023
are you referring to:

 TypeError: Cannot read properties of undefined (reading 'send')
at /app/index.js:50:13
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Node.js v18.12.1
SSharp3/7/2023
What.... the sweet hell, I just deleted node modules again and it worked
SSharp3/7/2023
:PES_Cry:
Bbrody3/7/2023
Are you deploying from git?
SSharp3/7/2023
wdym? to railway?
Bbrody3/7/2023
from git to railway?
SSharp3/7/2023
I sync changes to my repo and then railway redeploys
SSharp3/7/2023
is my flow
Bbrody3/7/2023
So currently you have a .gitignore with node_modules/ and theres now no node_modules folder on git?
SSharp3/7/2023
correct
SSharp3/7/2023
SSharp3/7/2023
Bbrody3/7/2023
and it works, no more undefined?
SSharp3/7/2023
nope.
SSharp3/7/2023
lol
Bbrody3/7/2023
okay well i dont know what was fixed but yay
SSharp3/7/2023
it was your energy
SSharp3/7/2023
the vibes
SSharp3/7/2023
Thank you so much for taking the time, I'm sorry this didn't sort itself out cleanly, but I did seriously learn some really solid lessons from you in the process
Bbrody3/7/2023
haha thank you, glad it worked out
SSharp3/7/2023
:Prayge: