question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

index 404 not found

See original GitHub issue

Describe the bug

Index not found 404 on page load

Actual behavior

On website load/reload, App renders the complete layout with nav bar and footer but index page (‘/’) is not found. When clicking in the Home (‘/’) link in the nav bar, the index is found and page loads correctly. There is no error reloading pages other than ‘/’.

Expected behavior

Index is rendered.

Steps to reproduce

File structure is as follows:

/pages

  • /404/index.tsx
  • /category/[id].tsx
  • /section/[id].tsx
  • _app.tsx
  • _document.tsx
  • _error.tsx
  • index.tsx <= not found on first load.

All pages have getServerSideProps, including pages/index.tsx

Screenshots/Code/Logs

Cloudfront log on page load: 2021-01-04 14:13:57 GET cloudfront.net / 404 - Mozilla/5.0%20(Windows%20NT%2010.0;%20Win64;%20x64)%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/87.0.4280.88%20Safari/537.36 - - Error N8oJ_zl2gxnHbFEHfkayx8VClBbwmQ5yrombR9LVirJoe0X5LHnAWA== domain.com https 1492 0.103 - TLSv1.3 TLS_AES_128_GCM_SHA256 Error HTTP/1.1 - - 56521 0.103 Error text/html - - -

Cloudfront log on Home click: 2021-01-04 14:13:59 GET cloudfront.net /_next/static/chunks/pages/index-d2b913f9934e0803151f.js 200 https://domain.com/ Mozilla/5.0%20(Windows%20NT%2010.0;%20Win64;%20x64)%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/87.0.4280.88%20Safari/537.36 - - Hit VpKpXjNuMuCKvB-urbfb2xJNyJRKLlfNzL9BzAdMA64mhUFDeptUEw== domain.com https 1443 0.002 - TLSv1.3 TLS_AES_128_GCM_SHA256 Hit HTTP/1.1 - - 25860 0.002 Hit application/javascript - - -

serverless.yaml

Website:
  component: '@sls-next/serverless-component@1.19.0-alpha.22'
  inputs:
    name: '#{ENVIRONMENT}#-website'
    build:
      env:
        API_URL: '#{API_URL}#'
        COGNITO_IDENTITY_POOL_ID: '#{COGNITO_IDENTITY_POOL_ID}#'
        COGNITO_IDENTITY_POOL_REGION: '#{COGNITO_IDENTITY_POOL_REGION}#'
        COGNITO_REGION: '#{COGNITO_REGION}#'
        COGNITO_USER_POOL_ID: '#{COGNITO_USER_POOL_ID}#'
        COGNITO_USER_POOL_WEB_CLIENT_ID: '#{COGNITO_USER_POOL_WEB_CLIENT_ID}#'
        COGNITO_USER_POOL_DOMAIN: '#{COGNITO_USER_POOL_DOMAIN}#'
        COGNITO_REDIRECT_SIGN_IN: '#{COGNITO_REDIRECT_SIGN_IN}#'
        COGNITO_REDIRECT_SIGN_OUT: '#{COGNITO_REDIRECT_SIGN_OUT}#'
        GOOGLE_TAG_MANAGER_ID: '#{GOOGLE_TAG_MANAGER_ID}#'
        GOOGLE_ANALYTICS_ID: '#{GOOGLE_ANALYTICS_ID}#'
        DIDOMI_API_KEY: '#{DIDOMI_API_KEY}#'
    domain: ['#{ENVIRONMENT}#', 'domain.com'] # [ sub-domain, domain ]
    bucketRegion: '#{CURRENT_REGION}#'
    bucketName: '#{ENVIRONMENT}#-website-front-#{CURRENT_REGION}#'
    cloudfront:
      distributionId: '#{DISTRIBUTION_ID}#' #optional
      # webACLId: '#{WEB_ACL_ID}#' # ARN of WAF
      originAccessIdentityId: '#{ORIGIN_ACCESS_IDENTITY_ID}#'
      aliases: ['#{ENVIRONMENT}#.domain.com']
      origins:
        - url: https://#{ENVIRONMENT}#-website-bo-front-#{CURRENT_REGION}#-s3.amazonaws.com/public
          pathPatterns:
            /images/*:
              defaultTTL: 86400
              maxTTL: 31536000
              minTTL: 0
              allowedHttpMethods: [GET, HEAD]
              compress: true
              forward:
                queryString: true
              viewerProtocolPolicy: 'redirect-to-https'
        - url: https://#{ENVIRONMENT}#-video-output-#{CURRENT_REGION}#-s3.amazonaws.com
          pathPatterns:
            /videos/*:
              defaultTTL: 86400
              maxTTL: 31536000
              minTTL: 0
              allowedHttpMethods: [GET, HEAD]
              compress: true
              forward:
                queryString: true
              viewerProtocolPolicy: 'redirect-to-https'

Versions

Additional context

Checklist

  • You have reviewed the README and FAQs, which answers several common questions.
  • Please first try using the most recent latest or alpha @sls-next/serverless-component release version, which may have already fixed your issue or implemented the feature you are trying to use. Note that the old serverless-next.js component and the serverless-next.js plugin are deprecated and no longer maintained.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

7reactions
L-Lucianocommented, Jan 7, 2021

Hi,

We found the solution. We create the cloudfront and there is a default root object : index.html. When I remove it, it works.

Sorry for the issue.

You can close it.

0reactions
L-Lucianocommented, Jan 7, 2021

I add the index.js file with txt extension.

index.txt

Regards

Read more comments on GitHub >

github_iconTop Results From Across the Web

What to do When Your Sitemap Index is Showing a 404 Error
What Causes a 404 Error? · The page has been deleted from the website's server · An incorrect URL address has been entered...
Read more >
Submitted URL Not Found (404): How to Fix It
A 404 error is an HTTP status code that means the page a user is trying to reach could not be found on...
Read more >
Getting 404 Page Not Found when accessing my index.php file
I assume you're using windows To get the folder path in windows, Go to the folder that contains index.php of your project. Hold...
Read more >
Error Case - 404 Page Not Found - Funio Knowledge Base
A 404 error is an HTTP status code that means that the webpage you are trying to reach could not be found on...
Read more >
What Are Google Soft 404 Errors (and How to Fix Them)
It's also possible to get a soft 404 when a page doesn't exist and when a user lands on it after clicking through...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found