Encountering a 404 error when trying to access assets on _next folder after

I have encountered an issue while trying to deploy my next app to gh pages. Only the index and 404 pages are displaying, while all other pages, images, js, and css files inside the _next folder are returning a 404 error.

After conducting some research, I came across a common solution which involves adding a .nojekyll file into the output folder to prevent Jekyll from ignoring files prefixed with _. I followed this solution, but the files still remain missing.

Below is my GitHub action for building and deploying the app:

 
        name: Deploy Next.js site to Pages
    
        on:
          push:
            branches: ["main"]
          
          workflow_dispatch:
        
        permissions:
          contents: read
          pages: write
          id-token: write
        
        concurrency:
          group: "pages"
          cancel-in-progress: true
          
        jobs:
          
          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 [ "${{ 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 [ "${{ 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
                  key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
                  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
            
          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 have verified that all intended files are included in the artifact that gets deployed. Despite this, they are not being displayed as expected. Can anyone help me identify what might be missing here?

Answer №1

  1. To get started, go to the public directory and create a new file named .nojekyll

  2. Next, open the package.json file and include the following line:

"deploy": "gh-pages -d dist -t true"
  1. Now, execute the following commands in your terminal:
yarn generate
yarn deploy

The file named .nojekyll will be moved to the dist folder.

Although I am using a Nuxt app, the process is similar for other platforms as well.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

React | Error: Build file blank during compilation

I am currently in the process of constructing and deploying a React app. After executing the build, when I attempt to open the index.html file from the build folder [see attached screenshot], it opens as a blank page. I have also tried adding "homepage": ...

What are some possible reasons for an API fetch failing to retrieve data from a URL, and what are potential solutions to address this issue?

Struggling to retrieve data from the server using frontend code. Below is an example of fetching user details, but it's not functioning as expected. const UserDetails = async () => { const apiUrl = process.env.REACT_APP_API_URL; try { cons ...

What causes the webpage to reset its scroll position when a component rerenders?

In the process of creating my personal blog with Next.js, I retrieve posts from my API using a page query for pagination. Then, I iterate through the items in this manner: let content = ( <ul> {props.posts.map((post) => { return &l ...

Incorporate a checkbox within the DropzoneDialog for enhanced functionality

I am working with a DropzoneDialog and I want to add a checkbox to it when the dialog opens. Unfortunately, this is not functioning as expected. <DropzoneDialog acceptedFiles={['image/*', 'application/pdf', ...

Preventing Redux from triggering re-renders in parent components when using multiple Slate.js editors

I have been facing a challenge as I attempt to integrate multiple Slate.js text editor fields on a single page. Currently, my main component features a button that, when clicked, appends a slate value to an array called slateValues in my redux store. In th ...

Guide for utilizing a sitemap in Firebase hosting for a React application

I recently launched a reactjs web application on firebase hosting. To ensure better indexing by search engines, I created a sitemap.xml file and placed it in the public folder. Then, I made changes to my firebase.json file to redirect the source to the sit ...

Trouble arises with Service Workers during the transition from Create React App to Next JS

After transitioning our landing page from create-react-app to Next.js, we encountered an issue with users receiving a cached version of the old website. This is due to the default service worker that was registered on their browsers when using create-react ...

What mistakes am I making in my usage of React hooks in this situation?

As part of my journey through the FullstackOpen course at the University of Helsinki, I am working on creating a simple Phonebook application. In troubleshooting my code, I've noticed that my 'filterBy' state is consistently one step behind, ...

What is the best way to customize the appearance of the material-ui select component using styled-components instead of material-ui classes in a React

I've been facing some challenges while trying to style my material-ui select component using styled-components instead of material- classes. The version I am working with is material-ui/core 4.12.3. When I use the old makeStyles component from materi ...

Reacting to the state of a child component from the parent component

Apologies for coming back with another question so soon, but I'm struggling here! I spent hours yesterday trying to figure out how to pass data from a child component to its parent using React hooks, but my brain just won't cooperate. What I&ap ...

Combining the power of ExpressJS with a dynamic blend of ejs and React for an

My current setup involves a NodeJS application with an Express backend and EJS for the frontend. The code snippet below shows an example route: router.get("/:name&:term", function(req, res) { Course.find({ courseName: req.params.name, courseTerm: req.p ...

Tips for sending custom props to a dynamic page in Next.js

I have created a component called Card.js which is responsible for linking to dynamic pages when a card is clicked. My goal is to pass a value, such as 'category', to the dynamic page [id].js so that I can implement additional logic there. Card. ...

Firestore is failing to accept incoming data when the setDoc method is employed

I am encountering an issue with my app's connectivity to the Firestore database when attempting to utilize setDoc. The database is successfully operational for next-auth, creating records as intended. However, the problem arises when trying to enable ...

Can someone please explain how to bring in the Sidebar component?

click here for image description check out this image info An issue arises as the module '@components/Sidebar' or its type declarations cannot be located.ts(2307) Various attempts were made, including: import Sidebar from '@components/Sid ...

Linking Redux to the highest level of my application is not functioning as expected

I have been attempting to troubleshoot this code for quite some time now, but I am struggling to identify the issue at hand. My main goal is to establish a connection between my top-level application and the redux store. However, every time I try, the stor ...

Seeking an improved approach to invoking a React component based on varying states. Open to suggestions for a more effective

I am currently working with a Modal Component from Material UI and my goal is to conditionally render this component based on the state provided by useState. This is what I have done so far - <ModalPopup open={deleteRole} onClose={handleDeleteClo ...

How to resolve undefined callback when passing it to a custom hook in React Native

I'm facing an issue with passing a callback to my custom hook: export default function useScreenshotDetection(onScreenshot) { useEffect(() => { ... onScreenshot(); ... }, []); } Strangely, the callback is not being detected ...

Generating an HTML version of a specific nextJS page by clicking a button that includes constantly changing data

I have a current project where I am tasked with filling a template.tsx file with the information gathered from a form, and then using that data to create an HTML file which can be downloaded to the user's device. Does anyone know how I can accomplish ...

Discovering the magic of nesting maps in React-Native without the need for

I am currently developing a react-native app that retrieves its data through an API. I am working on implementing a new feature where the information is grouped by date. The JSON data structure sent by the API looks like this: { "channel_count" ...

What can be done to solve the issue with NextJS: 'next_intl__WEBPACK_IMPORTED_MODULE_1__.useFormatter) is not a function'?

While exploring the NextJS documentation, I came across the next-intl library but unfortunately, I am unable to get it to work. Upon following the guidelines provided in the official docs of next-intl, an error is encountered: Unhandled Runtime Error: E ...