next-runtime icon indicating copy to clipboard operation
next-runtime copied to clipboard

[Bug]: Redirects not working in monorepo

Open kluplau opened this issue 2 years ago • 0 comments

Summary

I have a monorepo with 2 Netlify websites built using NextJS. Each of them with their own netlify.toml-file in their folder. I have redirects defined in next.config.mjs and it works locally.

The readme states that I need to configure the publish to be the full path of the .next folder. It's defined with the full path apps/web/.next in Netlify UI and the plugin doesn't break, but it also doesn't work. When I try to define full paths in the toml-files, then it uses the path relatively, which repeats the path, and the plugin throws because the folder apps/web/apps/web/.next doesn't exist, obviously.

There are no errors or warnings, it just doesn't work.

A link to a reproduction repository

NONE

Expected Result

Expected it to redirect as it does locally

Actual Result

It gives 404

Steps to reproduce

  1. Create a nextjs monorepo
  2. Add redirects to the next.config.js
  3. Verify it works locally
  4. Deploy to Netlify and define publish path there
  5. Verify that redirects doesn't work on Netlify

Next Runtime version

4.38.0

Is your issue related to the app directory?

  • [ ] Yes, I am using the app directory

More information about your build

  • [ ] I am building using the CLI
  • [X] I am building using file-based configuration (netlify.toml)

What OS are you using?

Mac OS

Your netlify.toml file

apps/web/netlify.toml
[template]
  incoming-hooks = ["Sanity"]

[build]
  ignore = "/bin/false"

[[plugins]]
  package = "@netlify/plugin-nextjs"

Your public/_redirects file

No response

Your next.config.js file

apps/web/next.config.mjs
import {DEFAULT_LOCALE, LOCALES} from "@repo/consts/web.mjs";
import * as sanityClient from "@lagobe/core/lib/sanity.client.mjs";

/** @type {import("next").NextConfig} */
const config = {
  // @TODO turn swcMinify back on once the agressive dead code elimination bug that casues
  // `ReferenceError: FieldPresenceWithOverlay is not defined` is fixed
  swcMinify: false,
  i18n: {
    locales: LOCALES,
    defaultLocale: DEFAULT_LOCALE,
    localeDetection: false,
  },
  images: {
    remotePatterns: [
      { hostname: "cdn.sanity.io" },
      { hostname: "source.unsplash.com" },
    ],
  },
  eslint: {
    /// Set this to false if you want production builds to abort if there's lint errors
    ignoreDuringBuilds: process.env.VERCEL_ENV === "production",
  },
  transpilePackages: ["@repo/core", "@repo/consts"],
  async redirects() {
    return await sanityClient.getRedirects();
  },
  trailingSlash: true,
  experimental: {
    scrollRestoration: true,
  },
};

export default config;

Builds logs (or link to your logs)

No response

Function logs

No response

.next JSON files

No response

kluplau avatar Jun 17 '23 14:06 kluplau