Persistent 'Cannot redeclare block-scoped variable PORT' Error
konghowlee6-pixel
HOBBYOP

2 months ago

This indicates that the PORT variable is being declared twice within index.ts during the build process.

## Steps Taken to Diagnose and Resolve

I have taken the following extensive steps to diagnose and resolve this issue, in collaboration with an AI assistant:

1. **Initial Code Fixes:**

* Identified and fixed a type mismatch error in routes/stock.ts related to missing required fields logisticsServiceType, appliedLogisticsFee) in stockOutRecords creation.

* Resolved multiple TypeScript type errors across routes/items.ts, routes/organizations.ts, routes/warehouses.ts, and routes/stock.ts where Express route parameters req.params.id) were being used directly with Drizzle ORM's eq() function, which expects a single string. Explicit type assertions id as string) were added.

* Created and refined tsconfig.json to ensure correct TypeScript compilation locally.

2. **Addressing the PORT Redeclaration Error:**

* Upon encountering the PORT redeclaration error in Railway, a thorough search of the codebase confirmed that index.ts indeed had two const PORT declarations. The duplicate declaration at line 20 was removed, leaving only the one at line 72 const PORT = Number(process.env.PORT) || 3000;).

3. **GitHub Synchronization and Authentication:**

* All code fixes were committed and pushed to the GitHub repository https://github.com/konghowlee6-pixel/arriival-wms ).

* Multiple attempts were made to push using different GitHub Personal Access Tokens (Classic), ensuring repo scope was granted. The latest token used was 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.

* Confirmed that the GitHub repository https://github.com/konghowlee6-pixel/arriival-wms ) is indeed a private repository, and Railway's connection correctly identified it as such.

4. **Railway Deployment Troubleshooting:**

* **Manual Redeployment:** Multiple manual redeployments were triggered from the Railway dashboard.

* **Repository Reconnection:** The GitHub repository connection in Railway was completely disconnected and then reconnected, including re-authorizing the GitHub App for private repository access.

* **Custom Build Command Modification:** The Custom Build Command in Railway's settings was changed from npm run build to npm install && npm run build to force a fresh installation of dependencies before building.

## Persistent Problem

Despite all these efforts, every subsequent deployment attempt on Railway continues to fail with the exact same Cannot redeclare block-scoped variable 'PORT' error. This suggests that Railway's build environment is either:

* Not pulling the latest code from the main branch, even after re-connecting the repository.

* Aggressively caching build artifacts or node_modules in a way that is not being cleared by standard methods or the npm install command in the custom build script.

## Request for Assistance

Given the persistence of this issue after extensive troubleshooting, I believe the problem lies within Railway's platform-level caching or synchronization mechanisms. I kindly request your team to investigate this matter by examining the backend build logs and environment for my arriival-wms service. Please advise on how to resolve this stubborn deployment failure.

Thank you for your time and assistance.

$10 Bounty

1 Replies

Status changed to Awaiting User Response Railway 2 months ago


danblock97
HOBBY

2 months ago

Some things to check based of past experience (not with railway but in general): Ensure TypeScript is not compiling dist/ , typically, tsconfig.json should compile onlysrc .

Ensure the commit SHA does match your latest, in the build command, you should be able to print this if Railway does not to tell you anyway. This will tell you if you're pulling the latest too.

Also: you pasted a GitHub PAT (ghp_…). Roll the key in github and don't reuse that one.


Status changed to Awaiting Railway Response Railway 2 months ago


Loading...