motdotla/dotenv

Fail on Linux ?

TheHellTower opened this issue · 5 comments

Hello,

I tried to port a bot to a Linux VPS instead of my Windows computer, but I encountered the following error(see logs):

Windows:

Connected to MongoDB
Logged in as XXXXXXX#7669
Loaded 3 events!
Loaded 10 commands!
Loaded 1 "/" commands!
Detected 2 "/" commands!

Linux:

Connected to MongoDB

=== unhandled Rejection ===
Error: Expected token to be set for this request, but none was present
=== unhandled Rejection ===

Logged in as XXXXXXX#7669
Loaded 3 events!
Loaded 10 commands!
Loaded 0 "/" commands!
Detected 2 "/" commands!

The thing is it got connected only because I used process.env.TOKEN directly in the token place but it seems like it's the only place where it's working it take it like the ENVIRONMENT VARIABLES was only available in the files having require("dotenv").config();?

Best Regards,
TheHellTower.

const path = require("path");
let EnvPath = path.resolve(__dirname, "..", ".env");
console.log(EnvPath);
require("dotenv").config({ path: EnvPath });

I even tried to specify the path and it's only working on Windows..

A bit more details:

Main File:

require("dotenv").config({ path: EnvPath });

const config = process.env,
  BoilerplateClient = require("./Structures/BoilerplateClient.js"),
  client = new BoilerplateClient(config);

client.start();

BoilerplateClient:

constructor(options = {}) {
....
this.config = options;
...
}
async start(token = this.config.token) {
    this.utils.loadCommands();
    this.utils.loadEvents();

    super.login(token).then(async () => {
      this.utils.loadSlashCommands();
    });
  }

If you want a more complete code, ref: https://github.com/TheHellTower/Discord.JS-v14-Bot-Boilerplate

Solved: Windows don't have case-sensitive keys !?
I suppose it should be enforced to ensure it will work "everywhere" but not sure !

yeah, one of those windows gotchas. not sure how to solve for this well in the library. glad you were able to get it fixed.

yeah, one of those windows gotchas. not sure how to solve for this well in the library. glad you were able to get it fixed.

To be honest I assume the only potential solution would be to make it case-sensitive since on Windows it isn't automatically it would be nice to enforce this ! I had a key that was like: camelCase and it did work under Linux too while nocaps didn't when It as FULLCAPS in the .env file, with this change it would be needed to respect the names and it would make it easier to transfer something from Windows to Linux for people like me who didn't know it before haha !