React app deployed on vercel via github actions giving 304 status code - reactjs

I'm trying to deploy my application on vercel through a GitHub workflow that runs whenever the code is pushed onto the remote repository. The workflow is successfully running, but when I visit the deployed link, an empty white page is shown. On inspecting the network tabs, I could see that the request to the URL is returning a 304 status code. I'm quite clueless why this is happening. Below is the folder structure of my project.
Below is my workflow file
name: Preview Deployment
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
on:
push:
branches-ignore:
- release
jobs:
Deploy-Preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Install Vercel CLI
run: npm install --global vercel#latest
- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
- name: Build Project Artifacts
run: vercel build --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy Project Artifacts to Vercel
run: vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}
During the build step, I could also notice the following log along with some other warnings:
Failed to load ./.env.
Despite the warnings(mostly related to the build file size being over the recommended size) and the above log, the build is successful. How do I fix this 304 issue? TIA
Further, to verify things, I also built the application locally and tried running it, and it worked as expected.

Related

Cannot deploy my React app in Azure Static Web Apps. Github actions throws this logs:

Everything is running ok until this happen:
npm WARN deprecated w3c-hr-time#1.0.2: Use your platform's native performance.now() and performance.timeOrigin.
npm WARN deprecated stable#0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
npm WARN deprecated har-validator#5.1.5: this library is no longer supported
npm WARN deprecated uuid#3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN deprecated request#2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated svgo#1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
added 1654 packages, and audited 1655 packages in 1m
Then, right at the end of the logs I got this from Oryx and my App doesn't get deployed.
---End of Oryx build logs---
Oryx has failed to build the solution.
For further information, please visit the Azure Static Web Apps documentation at https://docs.microsoft.com/en-us/azure/static-web-apps/
If you believe this behavior is unexpected, please raise a GitHub issue at https://github.com/azure/static-web-apps/issues/
Exiting
I dunno what would be the solution. Should I remove the dependencies warned from the package-lock.json? (that's where the warnings came from)
I'm expecting to deploy my app as usual
Here my workflow file:
name: Azure Static Web Apps CI/CD
on:
push:
branches:
- sandbox
pull_request:
types: [opened, synchronize, reopened, closed]
branches:
- sandbox
jobs:
build_and_deploy_job:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
runs-on: ubuntu-latest
name: Build and Deploy Job
steps:
- uses: actions/checkout#v2
with:
submodules: true
- name: Build And Deploy
id: builddeploy
uses: Azure/static-web-apps-deploy#v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_HAPPY_SEA_000C4D810 }}
repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments)
action: "upload"
###### Repository/Build Configurations - These values can be configured to match your app requirements. ######
# For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
app_location: "/" # App source code path
api_location: "" # Api source code path - optional
output_location: "build" # Built app content directory - optional
###### End of Repository/Build Configurations ######
close_pull_request_job:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
name: Close Pull Request Job
steps:
- name: Close Pull Request
id: closepullrequest
uses: Azure/static-web-apps-deploy#v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_HAPPY_SEA_000C4D810 }}
action: "close"
I have deployed the React App to Azure Static Web App without any issues.
Check the below workaround.
Create a React App in Local.
npx create-react-app my-react-app
Navigate to the Application root directory.
cd my-react-app
npm start
Create a new Repository in the GitHub and push the local code.
You will find the command to push the local code to repository in the GitHub.
git init
git add README.md
git commit -m "Update Code"
git branch -M main
git remote add origin https://github.com/Organization/RepositoryName.git
git push -u origin main
In Azure Portal Create a new Static Web App.
Under Deployment details, select the GitHub Account.Provide the Organization, Repository and Branch details.
Under Build details provide as mentioned below.
Build Prests - React
App location - api
Output location - build
Click on Review + create.
Initially when I run the Application, I got the content page.
Navigate to the GitHub = > Actions , check if the Build and Deployment is Successful or not.
Click on Re-run jobs .
Output:
Refer my GitHub Repository.

Github action for `yarn build` fails with missing React component

I have a React app that builds correctly locally with yarn build. I have the following job in my config for Github Actions to deploy the app to S3:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v1
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials#v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-2
- name: Install dependencies
run: yarn install
- name: Build
run: yarn build
- name: Deploy static site to S3 bucket
run: aws s3 sync build/ s3://my-s3-bucket --delete
The Build phase is failing with this error:
Module not found: Error: Can't resolve './components/Layout' in '/home/runner/work/storefront-app/storefront-app/src'
This module does exist under the src/components/ directory, so I'm not sure why it can't be found. I'm exporting it with export default Layout;
So I found that the issue was with filenames and Git.
Locally, all my files were named correctly: Nav.js, Layout.js, etc. On Github, they were downcased: layout.js. Git never picked up the change to the filename, and so the build on GH could not find ./components/Layout. Deleting the files and re-committing them solved the problem.

Build Failed - Non-Zero Exit Code Detected after 'npm build' in AWS Amplify

I am linked my AWS Amplify app to a new React Gatsby GitHub repo for continuous deployment. The app compiles fine locally, but I am getting an error in the 'Frontend' during the AWS build, saying that the amplify.sh file is 'killed' at the npm run build line, followed by 'Non-Zero Exit Code Detected' error. Below is a link to a screenshot of the error:
AWS Amplify Error
Below are the contents of my amplify.yml file in AWS:
version: 1
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
artifacts:
baseDirectory: public
files:
- '**/*'
cache:
paths:
- node_modules/**/*
Do I need to edit the amplify.yml file, or maybe add something to a package-lock or gatsby-node file?
Your script looks fine.
Would you be able to confirm that the IAM Role 'AWSAmplifyExecutionRole' has the AdministratorAccess permission? In order to do a CloudFormation deploy the role needs that permission in order to create all the resources in the stack.
OR
Please share the error log content, if possible.
I was able to solve this by running npm install (locally) and push to the branch. The error was invalid package-lock file version.
This was the step suggested in the build fail log.

No files were found with the provided path: build. No artifacts will be uploaded. - Github Action for deploying React App to Firebase

I'm following this tutorial on setting up CI/CD with github actions for a react app. I want the action to build and deploy my react app to my firebase project for hosting. I'm fairly sure I'm followed the directions, but when I trigger my action with a push, I get this error:
> Run actions/download-artifact#v2
> with:
> name: build
> path: build Starting download for build Error: Unable to find any artifacts for the associated workflow
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Firebase CI
on: push
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/f
steps:
- uses: actions/checkout#v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- name: Archive Build
uses: actions/upload-artifact#v2
with:
name: build
path: build
deploy:
name: Deploy
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Download Build
uses: actions/download-artifact#v2
with:
name: build
path: build
- name: Deploy to Firebase
uses: w9jds/firebase-action#master
with:
args: deploy --only hosting
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
I can install, build, and deploy manually from my console just fine. I thought this error might have something to do with my build directory's location, but its in the standard place. Any thoughts on what this might be?
Link to the full repo here
Additional Screenshots:
Seems like removing /build from my .gitignore solved the problem. I'm not %100 sure why though, as none of the examples of similar actions I have seen include their build folders.

Svelte/Sapper app 500 error on Google App Engine deploy via Gitlab CI

My Sapper app deploys Ok if I build it first and then deploy it from my local machine with gcloud app deploy.
My app.yaml just has: runtime:nodejs10 in it to deploy to the standard environment.
Now I can't achieve the same when I try to use Gitlab CI to deploy on git push.
In my .gitlab-ci.yml file I have 2 jobs: 1 to npm install and to run the build command and a second one to deploy to gcloud.
The 2 jobs complete but when I chack the version it has a 500 error and the logs say: Error: Cannot find module '/srv/__sapper__/build'.
So this has me going round in circles. I've tried moving svelte and sapper from dev deps to dependencies in package.json but it has not helped, I've looked at adding handlers in my app.yaml but am confused how, I've seen an issue on sapper github mentioning something related to svelte makefile and an issue with it needing to be built for the docker image to use it but no clear solution is proposed...
My .gitlab-ci.yml looks like this:
production-build:
stage: build-for-prod
image: node:10
script:
- npm install
- npm run build
only:
- master
prod-deploy:
stage: production
only:
- master
needs: ["production-build"]
image: google/cloud-sdk:alpine
environment: PROD
script:
- echo $SERVICE_ACCOUNT_KEY > /tmp/$CI_PIPELINE_ID.json
- gcloud auth activate-service-account --key-file /tmp/$CI_PIPELINE_ID.json
- gcloud --quiet --project sapper1-test app deploy app.yaml --verbosity debug --no-promote
after_script:
- rm /tmp/$CI_PIPELINE_ID.json
Correct me if i'm wrong, but to me this looks like you've misconfigured it. The jobs are running in separate containers and deploy doesn't have access to build results, that's why it is missing dependencies.
Artifacts might help to pass the built libraries around. But i would just build a custom image containing both Nodejs and Cloud SDK and combined two jobs on top of this image.

Resources