CodecademyCommunity / codecademy-discord-bot

Custom moderation bot for the official Codecademy Community Discord server.
https://codecademycommunity.github.io/
MIT License
11 stars 1 forks source link

Bot crashes when deploy action runs #291

Closed aedwardg closed 2 years ago

aedwardg commented 2 years ago

This only occurred after trying to set up the droplet for new deployment of bot running on Discord.js v13.

Symptoms: When deploy action was run, bot would crash with error:

Error: cannot find module node:events

Droplet was using nvm and node version 16.14.0. PM2 was updated.

The GH Action logs, however, indicated that nvm was not installed and pm2 was out of date: image image

The node:events was also indicative of the node version running being older than v. 16.6 (even though 16.14.0 was the nvm default).

aedwardg commented 2 years ago

Solved by altering the .bashrc file on the droplet. By default the .bashrc loads nothing for non-interactive shells. The ssh action used a non-interactive shell, so nvm was never loaded.

Moving the lines that load nvm to above the early exit solved the problem:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm

# If not running interactively, don't do anything
[ -z "$PS1" ] && return