kentcdodds / onewheel-blog

109 stars 26 forks source link

Failed at "Cypress start:mocks" during CI workflow #7

Open test-2287 opened 2 years ago

test-2287 commented 2 years ago

Hi, i followed the egghead course and the README file to deploy, but got throw new Error(prefix); at tiny-invariant

image

and i found npm run start:mocks have the same issue in my local dev env.

node version: v16.16.0 npm version: 8.11.0 platform: macOS bigSur

kentcdodds commented 2 years ago

Did you run the fly secrets set command before deploying?

test-2287 commented 2 years ago

@kentcdodds yes~ , i ran fly secrets set SESSION_SECRET=$(openssl rand -hex 32) --app blog-tutorial-c08c showed in the README and ran fly secrets set ADMIN_EMAIL=rachel@remix.run show in the course.

image
kentcdodds commented 2 years ago

Yeah, that's quite strange... I'm sorry, I don't know what it could be 😬

test-2287 commented 2 years ago

Yeah, that's quite strange... I'm sorry, I don't know what it could be 😬

i found cypress ran start:mocks failed cause it can't get the env variables, since the default NODE_ENV of remix serve run is production, it will always throw Error in tiny-invariant.js

var isProduction = process.env.NODE_ENV === 'production';
var prefix = 'Invariant failed';
function invariant(condition, message) {
    if (condition) {
        return;
    }
    if (isProduction) {
        throw new Error(prefix);
    }
    var provided = typeof message === 'function' ? message() : message;
    var value = provided ? prefix + ": " + provided : prefix;
    throw new Error(value);
}

module.exports = invariant;

i added the env as below in deploy.yml file and it works, i not sure if there is another better solution.

image
kentcdodds commented 2 years ago

Oh, did you update the .env.example? That's important because the github action will copy that file to .env before running the E2E tests.

amite commented 2 years ago

Oh, did you update the .env.example? That's important because the github action will copy that file to .env before running the E2E tests.

I am getting the same error. I tried updating the .env.example and it still crashes. I'll file a separate issue

bbaki commented 1 year ago

For anyone else trying to test the build locally, remix does not use .env file by default (link), also see this issue.

The solution is to use e.g. dotenv-cli like this: "start": "dotenv -e .env.production remix-serve build"