kentcdodds / onewheel-blog

109 stars 27 forks source link

(Issue solved) npm run build passes but npm run start fails (Error: Invariant failed) #9

Open amite opened 1 year ago

amite commented 1 year ago

UPDATE: the only way this got resolved was by adding ADMIN_EMAIL to the deploy step. Not sure this is the right way to do things in production. Any advice on setting secrets in github instead?

npm run build passes but npm run start fails. This is the error I get:

(npm run dev works and the site starts up _and functions end to end as expected).

❯ npm run start:mocks

> start:mocks
> binode --require ./mocks -- @remix-run/serve:remix-serve build

🔶 Mock server running

/Users/../Documents/code/js/remix/onewheel-blog/node_modules/tiny-invariant/dist/tiny-invariant.cjs.js:10
        throw new Error(prefix);
              ^
Error: Invariant failed
    at invariant (/Users/../Documents/code/js/remix/onewheel-blog/node_modules/tiny-invariant/dist/tiny-invariant.cjs.js:10:15)
    at getEnv (/Users/../Documents/code/js/remix/onewheel-blog/build/index.js:41:44)
    at Object.<anonymous> (/Users/../Documents/code/js/remix/onewheel-blog/build/index.js:48:14)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Function.Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/Users/../Documents/code/js/remix/onewheel-blog/node_modules/@remix-run/serve/dist/cli.js:48:13)

The place where it crashes I think is right here: https://github.com/amite/remix-full-stack-blog/blob/a58b9813b0f9c01d95fd7a52eb38e14fe37a3338/app/env.server.ts#L4

export function getEnv() {
  invariant(process.env.ADMIN_EMAIL, "ADMIN_EMAIL should be defined");
  console.log("process.env.ADMIN_EMAIL: ", process.env.ADMIN_EMAIL);

  return {
    ADMIN_EMAIL: process.env.ADMIN_EMAIL,
  };
}

Somehow in production mode its not able to read process.env.ADMIN_EMAIL I think.

When I try to push to github, I get the same error as filed in this issue: https://github.com/kentcdodds/onewheel-blog/issues/7

My repo is right here: https://github.com/amite/remix-full-stack-blog

I am running on node v18.11.0 My OS is Monterey Link to failed job: https://github.com/amite/remix-full-stack-blog/actions/runs/3298870582/jobs/5441547406

What should I do get rid of this invariant error?

amite commented 1 year ago

@kentcdodds should we update the readme docs or the deploy file to get this project up and running on fly.io?

kentcdodds commented 1 year ago

Sorry, I'm afraid I don't have time to look into this. If you figure out the issue and have a pull request to make then I would gladly review 👍