<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Vishnu :)</title>
    <description>The latest articles on Forem by Vishnu :) (@vishnu8742).</description>
    <link>https://forem.com/vishnu8742</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F101456%2F3b8a05f4-fa79-4d33-9761-5abb142a82f9.png</url>
      <title>Forem: Vishnu :)</title>
      <link>https://forem.com/vishnu8742</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/vishnu8742"/>
    <language>en</language>
    <item>
      <title>Netlify Nextjs Deployment — Page Not Found Issue Solution</title>
      <dc:creator>Vishnu :)</dc:creator>
      <pubDate>Sat, 21 Jan 2023 09:53:08 +0000</pubDate>
      <link>https://forem.com/vishnu8742/netlify-nextjs-deployment-page-not-found-issue-solution-3kf9</link>
      <guid>https://forem.com/vishnu8742/netlify-nextjs-deployment-page-not-found-issue-solution-3kf9</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--f5tdHkuE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AcvZpb4UX4Jc0_un-HlET0Q.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--f5tdHkuE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AcvZpb4UX4Jc0_un-HlET0Q.webp" alt="Netlify Nextjs Deployment" width="880" height="462"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nextjs deployment to netlify was made easy by netlify through github repo. But the issue is it’s not working for all and many of the developers are seeking help on the issue page not found even though deployment was successful.&lt;/p&gt;

&lt;p&gt;So I’ve made a work around for the issue. Its not a perfect solution but it works.&lt;/p&gt;

&lt;p&gt;I have created two repos one is for nextjs code and other is for the build generated files.&lt;/p&gt;

&lt;p&gt;I have created an action for the first repository where it builds &amp;amp; exports the code and pushed to second repository.&lt;/p&gt;

&lt;p&gt;This second repository is connected to netlify and it serves the generated html files.&lt;/p&gt;

&lt;p&gt;This action will be created from the first repository actions tab.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VvLVkTvN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AIu-n-UXy4f7PAE9OnU2kAQ.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VvLVkTvN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AIu-n-UXy4f7PAE9OnU2kAQ.webp" alt="Github Actions" width="880" height="136"&gt;&lt;/a&gt;&lt;br&gt;
Click New workflow and then click set up new workflow yourself.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Z8fA-Fpf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AtfSS0wOkH37H2zvCZTELmg.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Z8fA-Fpf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AtfSS0wOkH37H2zvCZTELmg.webp" alt="Create Workflow" width="880" height="120"&gt;&lt;/a&gt;&lt;br&gt;
Add below code and commit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name: Build &amp;amp; push to Another Repo
on:
  push:
    branches:
      - main
jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [16.x]

    steps:
      - uses: actions/checkout@v1
        with:
          fetch-depth: 0
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
      - name: npm install, build
        run: |
          npm ci
          npm run build &amp;amp;&amp;amp; npm run export
        env:
          CI: true
      - name: Publish
        uses: selenehyun/gh-push@master
        env:
          GITHUB_TOKEN: ${{ secrets.API_TOKEN_GITHUB }}
          COMMIT_FILES: out/*
          REPO_FULLNAME: userName/repoName
          BRANCH: main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are the build settings as we are deploying generated html files so no build setting are needed.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7Lv6KRyh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2ADfCVmkUTpJrIZtRhaCkb-g.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7Lv6KRyh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2ADfCVmkUTpJrIZtRhaCkb-g.webp" alt="Create Workflow" width="880" height="376"&gt;&lt;/a&gt;&lt;br&gt;
One more change required in the &lt;code&gt;next.config.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Add &lt;code&gt;target: 'serverless'&lt;/code&gt; in the exports.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = {
  reactStrictMode: true,
  target: 'serverless'
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s it. Now when ever you push code to first repo it generates a build and pushes to second repo. And when ever second repo gets a push netlify starts the deploy job and that’s how it works. I know its not the perfect fix but as I said it works.&lt;/p&gt;

</description>
      <category>netlify</category>
      <category>nextjs</category>
      <category>github</category>
      <category>actions</category>
    </item>
  </channel>
</rss>
