Description: I am currently facing an unexpected behavior in my TypeScript/Node.js application where an environment variable (SR_URL) seems to switch values intermittently. This issue has started recently, and I'm seeking assistance in identifying the root cause and potential solutions.
Problem Statement: I have defined the SR_URL duplicated variable in my .env file. The application is transpiled from TypeScript to JavaScript using the TypeScript compiler. The application is managed by PM2 on a remote server.
Issue Details: The variable recently sometimes takes the value from the top of the .env file (dummy-check-value-replace) and at other times takes the value from the bottom of the file (e00d5d10b97f1abb395a04fe72247a3ea71a9e0f). This behavior is inconsistent and started occurring without any recent changes to the codebase.
Sample Code from .env
SR_HASH=dummy-check-value-replace
SR_HASH=e00d5d10b97f1abb395a04fe72247a3ea71a9e0f
Environment:
| Environment | Version |
|---|---|
| Node.js | v18.17.0 |
| TypeScript | v4.5.2 |
| PM2 | 5.3.0 |
| Operating System | Ubuntu 20.04.6 LTS |
What I've Checked:
- Cleared build caches and restarted the PM2 process.
- Verified TypeScript compilation and inspected the generated JavaScript files.
- Reviewed the PM2 configuration to ensure correct environment variable loading.
Expectation:
- As per coding standards the last declared value should be taken when restarting or creating build.