R
Railway16mo 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
Percy16mo ago
Project ID: N/A
Percy
Percy16mo 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
Sharp16mo ago
e629e6f4-8257-472b-8ef9-34809b5acd29
Brody
Brody16mo ago
finally
Sharp
Sharp16mo ago
monkey1
Brody
Brody16mo ago
working on something right now, ill be back soon in the meantime, screenshots please
Sharp
Sharp16mo 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
Sharp16mo ago
Sharp
Sharp16mo 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
Brody16mo ago
obligatory question, have you modified anything in your local node_modules folder? also, callback hell async but no await
Sharp
Sharp16mo ago
no sir, never
Brody
Brody16mo ago
can i see a screenshot of the variables tab in the service
Sharp
Sharp16mo ago
just node v18
Sharp
Sharp16mo ago
Brody
Brody16mo ago
okay i was hoping so
Sharp
Sharp16mo ago
yep, always <a:aPES_Shake:513344618444881941>
Brody
Brody16mo ago
little side track though, im seeing a few 'XXX' meaning you stored secrets as plain text in your code?
Sharp
Sharp16mo 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
Brody16mo ago
still though, please use service variables going forward, its just good practice
Sharp
Sharp16mo ago
service variables?
Brody
Brody16mo ago
Brody
Brody16mo ago
like that but for your discord token
Sharp
Sharp16mo ago
shit, railway keeps getting better, ill be sure to peep docs for how that works and get on it immediately, thanks dude!
Brody
Brody16mo ago
add a variable in there then access it with process.env.<variable name>
Sharp
Sharp16mo ago
you're the best
Brody
Brody16mo ago
okay but thats not your issue
Sharp
Sharp16mo ago
i have many glad we could fix one
Brody
Brody16mo ago
now back on track, locally, delete the node_modules folder then run npm i and tell me if your code still works
Sharp
Sharp16mo ago
worked
Sharp
Sharp16mo ago
side note
Sharp
Sharp16mo ago
ill work on callback hell later PepeNervSmile
Brody
Brody16mo ago
its just const balance = await provider.getBalance('xxx');
Sharp
Sharp16mo 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
Brody16mo ago
ethBalance can be a const
Sharp
Sharp16mo ago
done ty sensei
Brody
Brody16mo ago
is client.channels.cache.get a promise?
Sharp
Sharp16mo ago
dont believe so would be if it was without cache actually i may be confusing versions of discord.js forget that
Brody
Brody16mo ago
okay so at this point im just googleing for the error, so will you take over that for now
Sharp
Sharp16mo 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
Brody16mo ago
Are you deploying from git?
Sharp
Sharp16mo ago
wdym? to railway?
Brody
Brody16mo ago
from git to railway?
Sharp
Sharp16mo ago
I sync changes to my repo and then railway redeploys is my flow
Brody
Brody16mo ago
So currently you have a .gitignore with node_modules/ and theres now no node_modules folder on git?
Sharp
Sharp16mo ago
correct
Sharp
Sharp16mo ago
Sharp
Sharp16mo ago
Brody
Brody16mo ago
and it works, no more undefined?
Sharp
Sharp16mo ago
nope. lol
Brody
Brody16mo ago
okay well i dont know what was fixed but yay
Sharp
Sharp16mo 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
Brody16mo ago
haha thank you, glad it worked out
Sharp
Sharp16mo ago
Prayge