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

2 years ago

Using Bun and Hono to run a server, don't quite know where this error is coming from.

42 Replies

spacemandev-git
PROOP

2 years ago

87a3785e-2be1-460c-b4a3-11c8952b90ec


2 years ago

please include more information, where are you seeing this error? what have you tried to do to fix this? etc etc


spacemandev-git
PROOP

2 years 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-git
PROOP

2 years ago

1242833299412488200


spacemandev-git
PROOP

2 years 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
};

^index.ts file


2 years ago

have you simply tried googling that error? as it's not an error that would strictly be related to the platform


spacemandev-git
PROOP

2 years ago

yup tried googling it, but didn't return anything helpful. also the code runs the server locally


2 years ago

what version of bun do you use locally?


spacemandev-git
PROOP

2 years ago

1.1.9


2 years ago

what version of bun is railway using?


spacemandev-git
PROOP

2 years ago

i didn't specify a version for bun in config, is there an easy way to find out what version it's using?

1242834267596132400


2 years ago

print the version in code


2 years ago

before the error happens


spacemandev-git
PROOP

2 years ago

ah gotcha, one sec


spacemandev-git
PROOP

2 years ago

looks like Bun 1.1.8

1242835900468039700


spacemandev-git
PROOP

2 years ago

i can try downgrade local version and see what happens but don't think that one minor version change would've caused this


2 years ago

I don't think so either


2 years ago

can you send that error as a message, I'm on mobile and I can't copy the form title apparently


spacemandev-git
PROOP

2 years ago

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


2 years ago

do you have a .env file in your repo?


spacemandev-git
PROOP

2 years ago

yes but it's not pushed


spacemandev-git
PROOP

2 years ago

ie, it's only local


2 years ago

what do you run to start your app locally?


spacemandev-git
PROOP

2 years ago

bun index.ts


spacemandev-git
PROOP

2 years ago

running locally with no issues

1242836793284628500


2 years ago

what version of node do you have installed locally?


spacemandev-git
PROOP

2 years ago

but i believe bun uses it's own runtime

1242837349348413400


2 years ago

well can't hurt to run node 18 and bun 1.1.8 locally and see what happens


spacemandev-git
PROOP

2 years ago

1242837753348227000


spacemandev-git
PROOP

2 years ago

trying to figure out how to downgrade bun, but node downgrade and it still works


2 years ago

nvm makes that quite easy


spacemandev-git
PROOP

2 years ago

1242838118743150600


2 years ago

have you tried writing a simple Dockerfile for Railway to use?


spacemandev-git
PROOP

2 years ago

bun 118 and node 18 still runs locally


spacemandev-git
PROOP

2 years ago

i have not, what should i put in the docker file?


spacemandev-git
PROOP

2 years ago

ie, downgrading doesn't seem to be doing the trick


2 years 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-git
PROOP

2 years 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


2 years 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-git
PROOP

2 years ago

just to close this out, couldnt' figure it out with bun so just reverted to hosting with traditional node


2 years ago

did you get to try a dockerfile?


2 years ago

marking that as solved since another use had the same issue and a Dockerfile solved it for them.


Loading...