0

I have multiple projects set up in a monorepo. I load all of them and browse out to Shared to load the initial layout. However, when I click a link to go to a different zone/app Customer, I receive Loading chunk app/testing/page failed. (error: https://localhost:5206/_next/static/chunks/app/testing/page.js). Sure enough, opening development tools, it doesn't exist. I also have the same issue with my styling, and I believe the root cause is the same. However, if I refresh the page, everything works correctly.

I have my rewrites set up in my next.config.ts:

  async rewrites() {
    return [
      {
        source: '/customer/:path*',
        destination: 'https://localhost:5216/:path*',
      },
      {
        source: '/customer-static/_next/:path*',
        destination: 'https://localhost:5216/_next/:path*',
      },

...plus more

The url is simply: href: '/customer/testing'.

I notice when I refresh the page however, that the _next/static folder is now within my customer folder (as written in my rewrites). How can I fix this so that my correct css/js chunks load correctly without a refresh?

1 Answer 1

0

Fix the rewrite order and add fallbacks

Make sure your static asset rewrites come before the page rewrites:

javascript

async rewrites() {
  return [
    // Static assets FIRST
    {
      source: '/customer-static/_next/static/:path*',
      destination: 'https://localhost:5216/_next/static/:path*',
    },
    {
      source: '/customer-static/_next/:path*',
      destination: 'https://localhost:5216/_next/:path*',
    },
    // Then pages
    {
      source: '/customer/:path*',
      destination: 'https://localhost:5216/:path*',
    },
    // Add a fallback for any missed static assets
    {
      source: '/_next/static/chunks/app/customer/:path*',
      destination: 'https://localhost:5216/_next/static/chunks/app/:path*',
    }
  ]
}
Sign up to request clarification or add additional context in comments.

1 Comment

This didn't work. I deleted my .next folders and rebuilt. I still get GET /_next/static/chunks/app/testing/page.js 404 in 3447ms

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.