404 on _next assets after deploying to Github Pages - reactjs

I am trying to deploy my next app to gh pages but only the index and 404 pages are displaying. All other pages, images, js and css files are returning a 404 error - everything inside the _next folder.
After some research, I found a popular solution to this issue was adding a .nojekyll file into the output folder to prevent jekyll from ignoring files prefixed with _ which I've tried but the files remain missing.
Here is my gh action to building and deploy the app -
name: Deploy Next.js site to Pages
on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: true
jobs:
# Build job
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./docs
steps:
- name: Checkout
uses: actions/checkout#v3
- name: Detect package manager
id: detect-package-manager
run: |
if [ -f "${{ github.workspace }}/docs/yarn.lock" ]; then
echo "::set-output name=manager::yarn"
echo "::set-output name=command::install"
echo "::set-output name=runner::yarn"
exit 0
elif [ -f "${{ github.workspace }}/docs/package.json" ]; then
echo "::set-output name=manager::npm"
echo "::set-output name=command::ci"
echo "::set-output name=runner::npx --no-install"
exit 0
else
echo "Unable to determine packager manager"
exit 1
fi
- name: Setup Node
uses: actions/setup-node#v3
with:
node-version: "16"
cache: ${{ steps.detect-package-manager.outputs.manager }}
- name: Restore cache
uses: actions/cache#v3
with:
path: |
.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
- name: Install dependencies
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
- name: Build with Next.js
run: ${{ steps.detect-package-manager.outputs.runner }} next build
- name: Static HTML export with Next.js
run: ${{ steps.detect-package-manager.outputs.runner }} next export
- name: nojekyll
run: touch ./out/.nojekyll
- name: Upload artifact
uses: actions/upload-pages-artifact#v1
with:
path: ./docs/out
# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages#v1
I've checked the artifact that gets deployed and all intended files are there.
What am I missing here?

in the public folder add file .nojekyll
then in package.json add
"deploy": "gh-pages -d dist -t true"
then run this command
yarn generate
yarn deploy
this file .nojekyll will be copied in the dist folder
I using nuxt app but the same idea
thanks

Related

Azure deployment of react app fails in deployment phase due to package path or zip deploy

I am new to azure and I made a setup on the azure portal with GitHub and set .yml. the pipeline runs successfully in the build phase but fails in the deployment phase.
here is my workflow file.
push:
branches: ["master"]
workflow_dispatch:
env:
AZURE_WEBAPP_NAME: wep-app-name # set this to your application's name
AZURE_WEBAPP_PACKAGE_PATH: "." # set this to the path to your web app project, defaults to the repository root
NODE_VERSION: "16.15.0" # set this to the node version to use
NODE_OPTIONS: "--max-old-space-size=8192"
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
- name: Set up Node.js
uses: actions/setup-node#v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: "npm"
#- name: yarn install, build, and test
# run: |
# node --max_old_space_size=8192
# yarn
#yarn run build
#zip artifact
- name: Zip artifact for deployment
run: zip release.zip ./build/* -r #get files and folder in build folder and
#compress into release.zip with linux zip command
- name: Upload artifact for deployment job
uses: actions/upload-artifact#v3
with:
name: node-app
path: build
deploy:
permissions:
contents: none
runs-on: ubuntu-latest
needs: build
environment:
name: "Development"
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact#v3
with:
name: node-app
path: .
- name: "Deploy to Azure WebApp"
uses: azure/webapps-deploy#v2
id: deploy-to-webapp
with:
app-name: "app-name"
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_B2318A4382DB625 }}
package: .

ERROR: failed to solve: failed to compute cache key: "/package.json" not found: not found

Hi I am working on Github actios to build react app. Below is the content of react app
# Fetching the latest node image on apline linux
FROM node:alpine AS development
# Declaring env
ENV NODE_ENV development
# Setting up the work directory
WORKDIR /my-app
# Installing dependencies
COPY ./package.json /my-app
RUN npm install
# Copying all the files in our project
COPY . .
# Starting our application
CMD npm start
Below is folder structure
I am using below github actions script to build the image
Below is my matrices file
{
"webapp": {
"name": "webapp",
"docker-image-name": "ghcr.io/my-org/webapp",
"dockerfile":"my-app/Dockerfile"
},
}
Below is build step
build-and-push-image:
name: "BUILD: ${{ matrix.name }}"
runs-on: ubuntu-latest
needs: prep
strategy:
matrix: ${{fromJson(needs.prep.outputs.matrix)}}
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout#v2
- name: Log in to the Container registry
uses: docker/login-action#f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action#98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ matrix.docker-image-name }}
- name: Build and push Docker image
uses: docker/build-push-action#ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
file: ${{ matrix.dockerfile }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
When I run the job I get below error
#9 [5/7] COPY ./package.json /my-app
#9 ERROR: "/package.json" not found: not found
ERROR: failed to solve: failed to compute cache key: "/package.json" not found: not found
Error: buildx call failed with: ERROR: failed to solve: failed to compute cache key: "/package.json" not found: not found
I see package.json exist in the solution but still its throwing error file doesn't exist I am not sure the root cause. Can someone help me to resolve this. Any help would be appreciated. Thanks
I changed to COPY ./my-app/package.json /my-app and it worked fine.

Set env variables in a github action before deploying to firebase hosting

I have a React application that makes use of the automatic deploy Github actions that Firebase provides. My issue is that I don't push my .env file to Github, and therefore there are no environment variables built into my code when the workflow script file runs yarn build in the Github action.
I tried to get around this by setting variables on my Github settings for the repo. I tried both Github secrets (under "Actions") and "Environments".
For actions -> repository secrets, I set up a secret called REACT_APP_GOOGLE_MAPS_API_KEY and added the following script to my steps:
REACT_APP_GOOGLE_MAPS_API_KEY=${{secrets.REACT_APP_GOOGLE_MAPS_API_KEY}} yarn && yarn build
Then I also created an environment called env, and on actions -> environment secrets I added the same, and changed the script to:
REACT_APP_GOOGLE_MAPS_API_KEY=${{env.REACT_APP_GOOGLE_MAPS_API_KEY}} yarn && yarn build
Neither of these worked; the env vars did not get bundled into the project and I get an error when I try to load maps on my live link because of a "missing api key".
How can I set secrets/variables in github and then utilise them in my workflow scripts?
For reference, here's the boilerplate script you get from firebase:
name: Deploy to Firebase Hosting on PR
"on": pull_request
jobs:
build_and_preview:
if: "${{ github.event.pull_request.head.repo.full_name == github.repository }}"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- run: yarn && yarn build # I added my vars here, before `yarn` #
- uses: FirebaseExtended/action-hosting-deploy#v0
with:
repoToken: "${{ secrets.GITHUB_TOKEN }}"
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_WEBPAGE_NAME }}"
projectId: webpage_name
You can define environment variables at three levels:
Workflow: available in the entire workflow.
name: Deploy to Firebase Hosting on PR
on: pull_request
env:
REACT_APP_GOOGLE_MAPS_API_KEY: ${{ secrets.REACT_APP_GOOGLE_MAPS_API_KEY }}
jobs:
build_and_preview:
...
Job: available in all the steps of the job.
name: Deploy to Firebase Hosting on PR
on: pull_request
jobs:
build_and_preview:
if: "${{ github.event.pull_request.head.repo.full_name == github.repository }}"
runs-on: ubuntu-latest
env:
REACT_APP_GOOGLE_MAPS_API_KEY: ${{ secrets.REACT_APP_GOOGLE_MAPS_API_KEY }}
steps:
...
Step: available only in a specific step within a job.
name: Deploy to Firebase Hosting on PR
on: pull_request
jobs:
build_and_preview:
if: "${{ github.event.pull_request.head.repo.full_name == github.repository }}"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- run: yarn && yarn build
env:
REACT_APP_GOOGLE_MAPS_API_KEY: ${{ secrets.REACT_APP_GOOGLE_MAPS_API_KEY }}
For your case, as you only need the API key during yarn build, declaring it in the step will be the best option.
Ref: https://docs.github.com/es/actions/learn-github-actions/environment-variables

GitHub Actions Deployment building with errors

My GitHub Actions completes successfully, but when I go to my website all I see is a blank white page. From the chrome dev tools I check the console and I see this error:
react-dom.production.min.js:216 Error: accountId is required
at Z (brightcove-react-player-loader.es.js:950)
at Q (brightcove-react-player-loader.es.js:1061)
at X (brightcove-react-player-loader.es.js:1126)
at r.o.loadPlayer (brightcove-react-player-loader.es.js:1350)
at r.o.componentDidMount (brightcove-react-player-loader.es.js:1519)
at hu (react-dom.production.min.js:219)
at As (react-dom.production.min.js:259)
at t.unstable_runWithPriority (scheduler.production.min.js:18)
at Ha (react-dom.production.min.js:122)
at Ts (react-dom.production.min.js:252)
uu # react-dom.production.min.js:216
The following is my yaml file which creates a .env file including the BrightCove ID but it isn't getting the ID from the .env for some reason...
# This is a basic workflow to help you get started with Actions
name: Deploy React Dev
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ development ]
pull_request:
branches: [ development ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
env:
REACT_APP_BRIGHTCOVE_ID: ${{ secrets.REACT_APP_BRIGHTCOVE_ID }}
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./app
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout#v2.3.4
# Create .env
- name: Create env file
run: |
touch .env
echo REACT_APP_AUTH0_DOMAIN=${{ secrets.REACT_APP_AUTH0_DOMAIN }} >> .env
echo REACT_APP_AUTH0_CLIENT_ID=${{ secrets.REACT_APP_AUTH0_CLIENT_ID }} >> .env
echo REACT_APP_AUTH0_AUDIENCE=${{ secrets.REACT_APP_AUTH0_AUDIENCE }} >> .env
echo REACT_APP_VIDEO_URL=${{ secrets.REACT_APP_VIDEO_URL }} >> .env
echo REACT_APP_STORE_NAME=${{ secrets.REACT_APP_STORE_NAME }} >> .env
echo REACT_APP_PAYPAL_CLIENT_ID=${{ secrets.REACT_APP_PAYPAL_CLIENT_ID }} >> .env
echo REACT_APP_HASURA_GRAPHQL_ENDPOINT=${{ secrets.REACT_APP_HASURA_GRAPHQL_ENDPOINT }} >> .env
echo REACT_APP_BRIGHTCOVE_ID=${{ secrets.REACT_APP_BRIGHTCOVE_ID }} >> .env
echo HASURA_GRAPHQL_ADMIN_SECRET=${{ secrets.HASURA_GRAPHQL_ADMIN_SECRET }} >> .env
# Set up Node JS
- uses: actions/setup-node#master
with:
node-version: '16.x'
cache: 'yarn'
cache-dependency-path: app/yarn.lock
# Use cached node_modules directory
- uses: actions/cache#v2
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
# Install & build
- run: yarn install
- run: yarn build
# Upload artifact
- name: Upload artifact
uses: actions/upload-artifact#v2
with:
name: webapp
path: app/build
deploy:
runs-on: ubuntu-latest
environment: Orange Develop
needs: build
steps:
- name: Download artifact
uses: actions/download-artifact#v2
with:
name: webapp
# Deploy webapp to Orange server
- name: SCP deployment to Orange
uses: appleboy/scp-action#master
with:
host: ${{ secrets.FTP_HOST }}
username: ${{ secrets.FTP_USER }}
key: ${{ secrets.FTP_KEY }}
source: '.'
target: '/opt/media-exchange/app/build'
rm: true`
Found the answer on this stackoverflow question: https://stackoverflow.com/a/66929604/14502018
I needed to set the environment that my secrets are stored in.
Inside the build job I added this line:
build:
runs-on: ubuntu-latest
environment: Orange Develop #MISSING LINE

Deploying react app to amazon s3 via github actions

So i have a Ionic React app which i would want that every time i push to the master branch it automatically uploads the files to amazons s3 bucket as well. I have come pretty far and my only problem is with the yml file in which i have to specifiy the directory to be uploaded. This is how it looks now:
name: Deploy
on:
push:
branches: [ master ]
workflow_dispatch:
jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v1
with:
node-version: 12
- run: npm install -g npm
- run: npm ci
- run: npm build
- 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: eu-north-1
- run: aws s3 sync <What to insert here?> s3://example-bucket
Now i have tried with putting jsut an . there but it uploaded for 20 mins without reaching an end and it was not with a strcutured folders in the s3 buckets but every file for itself. Any solutions? I feel like it is a easy task but im no backend developer
I have the index file here: payeat-s3/public/index.html
I have used this YAML configuration to deploy my react site to S3 using Github Actions:
on:
push:
branches:
- develop
name: Build and Deploy Site to S3
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#master
- name: Setup Node
uses: actions/setup-node#v2
with:
node-version: '12.x'
- name: Build App
run: |
yarn && yarn build && ls *
env:
CI: ""
- name: Copy to S3
uses: jakejarvis/s3-sync-action#master
with:
args: --acl public-read --follow-symlinks --delete
env:
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
SOURCE_DIR: ${{ secrets.SOURCE_DIR }}
I have added more details in this blog - https://blog.coderise.io/deploy-react-app-aws-s3-using-github-actions/

Resources