Saltad

Saltad

【Bug Log】Errors caused by outdated nodejs version of pm2 process.

Date: 2023.12.17

Issue: When developing a discord bot, encountered the error "Error: Cannot find module 'readline/promises'" on the server side. However, there were no errors locally.

Solution process:

  1. "readline/promises" is a library used by the bot's dependency, elephant-sdk. Based on this search result, it is initially believed that it may be related to the version of nodejs.

Checked the server's nodejs version, which is v16.19.1, and suspected that the error was caused by a too low version of nodejs on the server.

root@nunti-bot:~# node -v
v16.19.1

  1. Upgraded nodejs to v21.4.0 using nvm. However, the bot's error still persisted.
  2. Attempted to minimize the error. Ran the code in the Node.js REPL (interactive interpreter):
    const readline = require('readline/promises');
    There were no errors.
  3. Downloaded the elephant sdk separately, installed dependencies using npm (the same package manager as the bot), and ran the example.ts provided with the repository, which ran successfully.
  4. At this point, there was no clear direction. After leaving it for a while, I suddenly realized before going to bed that the bot had been restarted during testing using pm2. It is likely that pm2 was still using the old version of nodejs. To verify this hypothesis, used pm2 show 'app-name' to check and indeed found a line in the returned result: │ node.js version │ 16.19.1.
  5. Based on this search result, upgraded pm2 and restarted the pm2 process:
    pm2 update
    pm2 restart app --update-env
    
    Then checked again using pm2 show, and found that this time the nodejs version was finally successfully upgraded. Tested the bot again, and it worked successfully.
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.