Skip to content

assetPrefix + rewrites is bugged in development mode since 13.4.13 #55320

@sebpettersson

Description

@sebpettersson

Link to the code that reproduces this issue or a replay of the bug

https://github.com/sebpettersson/nextjs-dev-mode-bug

To Reproduce

If you use assetPrefix and rewrites in development mode you get "Error: Invariant: attempted to hard navigate to the same URL".

Sample config:

module.exports = {
  reactStrictMode: true,
  assetPrefix: "/dev-mode-bug",
  rewrites: async () => [
    {
      source: `/dev-mode-bug/_next/static/:path*`,
      destination: "/_next/static/:path*",
    },
  ],
};

It looks like the files starting with _dev in _next/static/development/ is not being rewritten correctly and return 404s:

Screenshot 2023-09-13 at 14 00 04

Current vs. Expected behavior

I expected assetPrefix and rewrites to not trigger any errors or 404s on critical files.

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 22.6.0: Wed Jul  5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000
Binaries:
  Node: 18.13.0
  npm: 8.19.3
  Yarn: N/A
  pnpm: 8.6.12
Relevant Packages:
  next: 13.4.20-canary.26
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.1.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Not sure

Additional context

This issue was introduced in 13.4.13-canary.0. 13.4.12 works as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue was opened via the bug report template.locked

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions