Error: Env vars from ${X(l)} overwrite the ones from ${X(a)}

Using Bun and Hono to run a server, don't quite know where this error is coming from.
Solution:
have you tried writing a simple Dockerfile for Railway to use?
Jump to solution
38 Replies
Percy
Percy7mo ago
Project ID: 87a3785e-2be1-460c-b4a3-11c8952b90ec
Spacemandev
SpacemandevOP7mo ago
87a3785e-2be1-460c-b4a3-11c8952b90ec
Brody
Brody7mo ago
please include more information, where are you seeing this error? what have you tried to do to fix this? etc etc
Spacemandev
SpacemandevOP7mo ago
seeing this error after deploy is finished; prisma generates it's client and hono starts up the server. it crashes right after. i really don't know where this is coming from otherwise i would try to provide more information
Spacemandev
SpacemandevOP7mo ago
No description
Spacemandev
SpacemandevOP7mo ago
import { Hono } from "hono";
import type { User } from "@prisma/client";
type Variables = {
stytchId: string,
user: User
}
const app = new Hono<{ Variables: Variables }>();

import * as api from "./api";
import { DB, ERRGEN, STYTCH } from "./constants";

app.get("/", (c) => c.text("Hello from Spaceman Gaming!"));

// All user paths check the JWT to fetch the user
// They set the user as a variable on the request, so it can be processed by the called method
app.use("/user/*", async (c, next) => {
try {
const jwt = c.req.header("x-lots-auth");
if (!jwt) {
throw ERRGEN(401, "JWT not found!")
}

const decoded = await STYTCH.sessions.authenticateJwtLocal({ session_jwt: jwt })
c.set("stytchId", decoded.user_id);
await next();
} catch (e: any) {
if (!e.code) { e.code = 500; }
console.log(`ERROR: ${e.code} ${e.message}`)
return c.json({ success: false, error: e.message }, e.code);
}
});

app.use("/user/me/*", async (c, next) => {
try {
const user = await DB.user.findUnique({ where: { stytchId: c.get("stytchId") } });
if (!user) {
throw ERRGEN(400, "User not found!")
}
c.set('user', user);
await next();
} catch (e: any) {
if (!e.code) { e.code = 500; }
console.log(`ERROR: ${e.code} ${e.message}`)
return c.json({ success: false, error: e.message }, e.code);
}
})

// TODO: This currently returns the full user object; we want to return some subset of this information probably?
// Or attach more info to this through other database models (such as wallets)
app.get("/user/me", async (c) => {
return await api.getUser(c);
})

app.post("/user/register", async (c) => {
return await api.registerUser(c);
})

console.log(`Hono running on port ${process.env.PORT || 3000}`);
export default {
port: process.env.PORT || 3000,
fetch: app.fetch
};
import { Hono } from "hono";
import type { User } from "@prisma/client";
type Variables = {
stytchId: string,
user: User
}
const app = new Hono<{ Variables: Variables }>();

import * as api from "./api";
import { DB, ERRGEN, STYTCH } from "./constants";

app.get("/", (c) => c.text("Hello from Spaceman Gaming!"));

// All user paths check the JWT to fetch the user
// They set the user as a variable on the request, so it can be processed by the called method
app.use("/user/*", async (c, next) => {
try {
const jwt = c.req.header("x-lots-auth");
if (!jwt) {
throw ERRGEN(401, "JWT not found!")
}

const decoded = await STYTCH.sessions.authenticateJwtLocal({ session_jwt: jwt })
c.set("stytchId", decoded.user_id);
await next();
} catch (e: any) {
if (!e.code) { e.code = 500; }
console.log(`ERROR: ${e.code} ${e.message}`)
return c.json({ success: false, error: e.message }, e.code);
}
});

app.use("/user/me/*", async (c, next) => {
try {
const user = await DB.user.findUnique({ where: { stytchId: c.get("stytchId") } });
if (!user) {
throw ERRGEN(400, "User not found!")
}
c.set('user', user);
await next();
} catch (e: any) {
if (!e.code) { e.code = 500; }
console.log(`ERROR: ${e.code} ${e.message}`)
return c.json({ success: false, error: e.message }, e.code);
}
})

// TODO: This currently returns the full user object; we want to return some subset of this information probably?
// Or attach more info to this through other database models (such as wallets)
app.get("/user/me", async (c) => {
return await api.getUser(c);
})

app.post("/user/register", async (c) => {
return await api.registerUser(c);
})

console.log(`Hono running on port ${process.env.PORT || 3000}`);
export default {
port: process.env.PORT || 3000,
fetch: app.fetch
};
^index.ts file
Brody
Brody7mo ago
have you simply tried googling that error? as it's not an error that would strictly be related to the platform
Spacemandev
SpacemandevOP7mo ago
yup tried googling it, but didn't return anything helpful. also the code runs the server locally
Brody
Brody7mo ago
what version of bun do you use locally?
Spacemandev
SpacemandevOP7mo ago
1.1.9
Brody
Brody7mo ago
what version of bun is railway using?
Spacemandev
SpacemandevOP7mo ago
i didn't specify a version for bun in config, is there an easy way to find out what version it's using?
No description
Brody
Brody7mo ago
print the version in code before the error happens
Spacemandev
SpacemandevOP7mo ago
ah gotcha, one sec
Spacemandev
SpacemandevOP7mo ago
looks like Bun 1.1.8
No description
Spacemandev
SpacemandevOP7mo ago
i can try downgrade local version and see what happens but don't think that one minor version change would've caused this
Brody
Brody7mo ago
I don't think so either can you send that error as a message, I'm on mobile and I can't copy the form title apparently
Spacemandev
SpacemandevOP7mo ago
Env vars from ${X(l)} overwrite the ones from ${X(a)}
Brody
Brody7mo ago
do you have a .env file in your repo?
Spacemandev
SpacemandevOP7mo ago
yes but it's not pushed ie, it's only local
Brody
Brody7mo ago
what do you run to start your app locally?
Spacemandev
SpacemandevOP7mo ago
bun index.ts
Spacemandev
SpacemandevOP7mo ago
running locally with no issues
No description
Brody
Brody7mo ago
what version of node do you have installed locally?
Spacemandev
SpacemandevOP7mo ago
but i believe bun uses it's own runtime
No description
Brody
Brody7mo ago
well can't hurt to run node 18 and bun 1.1.8 locally and see what happens
Spacemandev
SpacemandevOP7mo ago
No description
Spacemandev
SpacemandevOP7mo ago
trying to figure out how to downgrade bun, but node downgrade and it still works
Brody
Brody7mo ago
nvm makes that quite easy
Spacemandev
SpacemandevOP7mo ago
No description
Solution
Brody
Brody7mo ago
have you tried writing a simple Dockerfile for Railway to use?
Spacemandev
SpacemandevOP7mo ago
bun 118 and node 18 still runs locally i have not, what should i put in the docker file? ie, downgrading doesn't seem to be doing the trick
Brody
Brody7mo ago
I unfortunately don't have a bun dockerfile on hand, but there would be many great examples online, once you see one you will know how to use or modify them to your needs
Spacemandev
SpacemandevOP7mo ago
right, i'm just trying to figure out the motivation on the bun dockerfile :- i'm not doing anything special with bun, the env error seems to be (i could be totally wrong) from a conflict with how railway is injecting env and how bun is expecting it; unsure what part of dockerfile to modify to change that conflict
Brody
Brody7mo ago
Railway doesn't do anything special they are just environment variables, I think this is something nixpacks is doing wrong and a Dockerfile would answer that question
Spacemandev
SpacemandevOP7mo ago
just to close this out, couldnt' figure it out with bun so just reverted to hosting with traditional node
Brody
Brody7mo ago
did you get to try a dockerfile?
Brody
Brody7mo ago
marking that as solved since another use had the same issue and a Dockerfile solved it for them.
Want results from more Discord servers?
Add your server