-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Pre-flight checklist
- I have searched the existing issues
- I have read the contributing guidelines
[Bug]: Production server fails to start due to environment variables not being loaded
Describe the bug
When running the server with the production command (npm start), the application crashes immediately. The error message Error: Parameter 'sid' is not valid. from the Twilio library indicates that environment variables from the .env file are not being loaded. This issue does not occur when using the development command (npm run dev), which uses tsx to explicitly load the .env file. This suggests a race condition or misconfiguration in how the production build loads dotenv.
Steps to reproduce
- Navigate to the
serverdirectory. - Create a valid
.envfile by copying.env.exampleand filling in the required variables (at minimumMONGODB_URIandJWT_SECRET). - Install dependencies with
npm install. - If a
builddirectory doesn't exist, create one withnpm run build. - Attempt to start the server using the production command:
npm start. - Observe the application crash with the error shown in the logs.
Expected behavior
The server should start up successfully on the configured port (e.g., 1234), connect to the database, and initialize all services without crashing. The environment variables from the .env file should be loaded and available to the application at runtime, just as they are with npm run dev.
Relevant log output / screenshots
> [email protected] start
> node build/index.js
/Users/ihsankahveci/respondent-driven-sampling/server/node_modules/twilio/lib/rest/verify/v2/service.js:36
throw new Error("Parameter 'sid' is not valid.");
^
Error: Parameter 'sid' is not valid.
at new ServiceContextImpl (/Users/ihsankahveci/respondent-driven-sampling/server/node_modules/twilio/lib/rest/verify/v2/service.js:36:19)
at instance.get (/Users/ihsankahveci/respondent-driven-sampling/server/node_modules/twilio/lib/rest/verify/v2/service.js:315:16)
at V2.instance [as _services] (/Users/ihsankahveci/respondent-driven-sampling/server/node_modules/twilio/lib/rest/verify/v2/service.js:313:41)
at file:///Users/ihsankahveci/respondent-driven-sampling/server/build/routes/v1/auth.js:15:40
at ModuleJob.run (node:internal/modules/esm/module_job:377:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:671:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:101:5)
Node.js v24.11.1Software version
v1 - 527f8969a37bc8aeb6b92759650caae139ece6bb
Environment
macOS
None
Other environment details
No response