R
Railway2y ago
Sharp

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

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.
54 Replies
Percy
Percy2y ago
Project ID: N/A
Percy
Percy2y ago
Farazpatankar suggested that the start script might be the issue and to check the package.json file. Wyzlle suggested setting the NIXPACKS_PKGS variable to util-linux-minimal in variables, and JustJake suggested adding the variable.
⚠️ experimental feature
Sharp
SharpOP2y ago
e629e6f4-8257-472b-8ef9-34809b5acd29
Brody
Brody2y ago
finally
Sharp
SharpOP2y ago
monkey1
Brody
Brody2y ago
working on something right now, ill be back soon in the meantime, screenshots please
Sharp
SharpOP2y ago
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
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
/// 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();
/// 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();
Sharp
SharpOP2y ago
Sharp
SharpOP2y ago
There we go, ofc just lmk if I'm missing anything take your time, no rush at all, apologies for the wait haha
Brody
Brody2y ago
obligatory question, have you modified anything in your local node_modules folder? also, callback hell async but no await
Sharp
SharpOP2y ago
no sir, never
Brody
Brody2y ago
can i see a screenshot of the variables tab in the service
Sharp
SharpOP2y ago
just node v18
Sharp
SharpOP2y ago
Brody
Brody2y ago
okay i was hoping so
Sharp
SharpOP2y ago
yep, always <a:aPES_Shake:513344618444881941>
Brody
Brody2y ago
little side track though, im seeing a few 'XXX' meaning you stored secrets as plain text in your code?
Sharp
SharpOP2y ago
yeah, this is a one-off discord bot for a super small function someone could get hold of that secret and it really wouldnt matter haha
Brody
Brody2y ago
still though, please use service variables going forward, its just good practice
Sharp
SharpOP2y ago
service variables?
Brody
Brody2y ago
Brody
Brody2y ago
like that but for your discord token
Sharp
SharpOP2y ago
shit, railway keeps getting better, ill be sure to peep docs for how that works and get on it immediately, thanks dude!
Brody
Brody2y ago
add a variable in there then access it with process.env.<variable name>
Sharp
SharpOP2y ago
you're the best
Brody
Brody2y ago
okay but thats not your issue
Sharp
SharpOP2y ago
i have many glad we could fix one
Brody
Brody2y ago
now back on track, locally, delete the node_modules folder then run npm i and tell me if your code still works
Sharp
SharpOP2y ago
worked
Sharp
SharpOP2y ago
side note
Sharp
SharpOP2y ago
ill work on callback hell later PepeNervSmile
Brody
Brody2y ago
its just const balance = await provider.getBalance('xxx');
Sharp
SharpOP2y ago
const getBalance = async () => {
const initBalance = await provider.getBalance('XXX')
let ethBalance = ethers.formatEther(initBalance);
const getBalance = async () => {
const initBalance = await provider.getBalance('XXX')
let ethBalance = ethers.formatEther(initBalance);
is that less hellish lol sorry, i swear i didnt open this for JS lessons KEKW
Brody
Brody2y ago
ethBalance can be a const
Sharp
SharpOP2y ago
done ty sensei
Brody
Brody2y ago
is client.channels.cache.get a promise?
Sharp
SharpOP2y ago
dont believe so would be if it was without cache actually i may be confusing versions of discord.js forget that
Brody
Brody2y ago
okay so at this point im just googleing for the error, so will you take over that for now
Sharp
SharpOP2y ago
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
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
What.... the sweet hell, I just deleted node modules again and it worked <:PES_Cry:493359762432327691>
Brody
Brody2y ago
Are you deploying from git?
Sharp
SharpOP2y ago
wdym? to railway?
Brody
Brody2y ago
from git to railway?
Sharp
SharpOP2y ago
I sync changes to my repo and then railway redeploys is my flow
Brody
Brody2y ago
So currently you have a .gitignore with node_modules/ and theres now no node_modules folder on git?
Sharp
SharpOP2y ago
correct
Sharp
SharpOP2y ago
Sharp
SharpOP2y ago
Brody
Brody2y ago
and it works, no more undefined?
Sharp
SharpOP2y ago
nope. lol
Brody
Brody2y ago
okay well i dont know what was fixed but yay
Sharp
SharpOP2y ago
it was your energy the vibes 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
Brody
Brody2y ago
haha thank you, glad it worked out
Sharp
SharpOP2y ago
Prayge
Want results from more Discord servers?
Add your server