Node app crashes on Railway: "isAuthenticated is not defined" despite being imported
djjrip
FREEOP

3 months ago

My Express/TypeScript app builds successfully on Railway but crashes immediately on startup:

x emoji FATAL SERVER STARTUP ERROR: ReferenceError: isAuthenticated is not defined

at registerRoutes (file:///app/dist/index.js:4558:36)

The function IS defined in server/replitAuth.ts and imported in server/routes.ts:

import { isAuthenticated } from "./replitAuth";

Build uses esbuild to bundle everything. Works fine locally, only crashes on Railway.

Any ideas? Is this an esbuild bundling issue or Railway-specific?

Repo: https://github.com/djjrip/gg-loop-platform

$10 Bounty

2 Replies

Railway
BOT

3 months ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


bytekeim
PRO

3 months ago

Hyy,

So the build works locally, but the app dies on Railway with “isAuthenticated is not defined” because Railway runs on a fully case-sensitive Linux filesystem. macOS and Windows aren’t, so a mismatched import works locally but fails in production.

The first thing to check is the casing of the file vs the import. For example, if the file is named ReplitAuth.ts but the import is:

import { isAuthenticated } from "./replitAuth";

it will load locally but on Railway the module won’t load at all, and the bundled file will throw that ReferenceError.

To verify, run this on a Linux shell or WSL:

ls -la server

Make sure the filename and the import path match exactly, letter for letter.

Next, make sure the export in server/replitAuth.ts is actually a named export:

export const isAuthenticated = ...

or

export function isAuthenticated(...) { ... }

If it’s a default export but you’re importing a named export, the value will also be undefined in the bundle.

If the casing and export are correct, check your esbuild config. For Node apps you want:

platform: "node",
bundle: true,
format: "cjs",
sourcemap: true

Recent esbuild versions sometimes externalize modules differently, which can cause undefined values when there is a circular reference or when initialization order changes.

A quick sanity check: add this at the top of replitAuth.ts:

console.log("replitAuth loaded");

If you don’t see that line in Railway logs, the module isn’t being loaded at all, which points back to the import path mismatch.

Most of the time, fixing the filename/import casing resolves this instantly. If not, share the lines around 4558 in dist/index.js and the esbuild config and it will be easy to spot which symbol got dropped during the bundle.


Loading...