Skip to content

[Bug]: dotenv should not be initialized by alpaca #283

@parris

Description

@parris

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

When loading the alpaca-trade-api dotenv is called on the first line of dist/alpaca-trade-api.js

This means if you have a custom dotenv setup eg. different tokens for dev vs prod or multiple dotenv files you aren't able to guarantee a specific configuration. Depending on module load order, alpaca sometimes has won out. This has caused me to patch alpaca and delete that line.

My pnpm patch for reference

diff --git a/dist/alpaca-trade-api.js b/dist/alpaca-trade-api.js
index 85b69008eebcbd434a24cb01b53ebdb655d8fc2b..af8fcb41dd42096be2b66cda8b307fabb37e3f07 100644
--- a/dist/alpaca-trade-api.js
+++ b/dist/alpaca-trade-api.js
@@ -1,5 +1,5 @@
 "use strict";
-require("dotenv").config();
+// require("dotenv").config();
 const api = require("./api");
 const account = require("./resources/account");
 const position = require("./resources/position");

Expected Behavior

When I load alpaca, I can use my own method to load in environment variables and init them into alpaca. At minimum some way to disable this behavior would be great.

SDK Version I encountered this issue in

"@alpacahq/alpaca-trade-api": "^3.1.3"

Steps To Reproduce

1. Create a package with a 2 dotenv files, load them in a custom way eg:

import dotenv from "dotenv";

if (process.env.NODE_ENV === "development") {
  dotenv.config({ path: "../.env.dev" });
}

dotenv.config({ path: "../.env" });

2. Import this file and alpaca
3. Notice alpaca wins depending on dependency graph (I don't totally know what it takes for alapaca to get loaded first)

Filled out the Steps to Reproduce section?

  • I have entered valid steps to reproduce my issue or have attached a minimally reproducible case in code that shows my issue happening; and understand that without this my issue will be flagged as invalid and closed after 30 days.

Anything else?

Sorry for posting a bunch of issues at once - figured i drop in all the notes while i was here :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions