iis return 404 when url has [] cause next.js dynamic routes chunk load error
Asked Answered
V

2

1

I host a next.js app on iis server, and any urls with [] (%5B, %5D) return a 404 error which includes the generated js files for any dynamic page

for example there is file at /_next/static/chunks/pages/Category/[category]-someid.js

/_next/static/chunks/pages/Category/%5Bcategory%5D-someid.js net::ERR_ABORTED 404 (Not Found)

This is a similar problem https://github.com/vercel/next.js/issues/54008, but it is with docker not iis.

I am able to get other type of chunk files, just not those dynamic routes chunk with []. how to enable iis accept special characters?

I have set allowDoubleEscaping= true

Vindication answered 4/4 at 20:47 Comment(2)
So which version of Next.js are you using? And you are using iisnode?Sunderance
yea I am using iisnode, and urlrewrite. and version "next": "13.5.2". it works fine at local tho.Vindication
S
0
  • You might upgrade to at least Next.js 13.5.4, as the GitHub issue you linked indicates. That's a bug in Next.js itself, so applicable to all scenarios, not merely Docker hosting.
  • You might give up the out of maintenance iisnode (and URL rewrite rules) and switch to just HttpPlatformHandler
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" requireAccess="Script" />
        </handlers>
        <httpPlatform stdoutLogEnabled="true" stdoutLogFile=".\node.log" startupTimeLimit="20" processPath="C:\Users\<user name>\AppData\Roaming\nvm\v18.20.1\node.exe" arguments=".\node_modules\next\dist\bin\next start">
            <environmentVariables>
                <environmentVariable name="PORT" value="%HTTP_PLATFORM_PORT%" />
                <environmentVariable name="NODE_ENV" value="Production" />
            </environmentVariables>
        </httpPlatform>
    </system.webServer>
</configuration>

In this way, things like Dynamic Routes start to work properly. More details can be found in

https://docs.lextudio.com/blog/running-next-js-web-apps-on-iis-with-httpplatformhandler/

Sunderance answered 5/4 at 23:3 Comment(1)
unfortunately after upgrading to the latest next.js 14.x still having problem with it, but error code change from 404 to 500. I might try using httpplatformhandler later on.Vindication
T
-1

You can also try to change the registry file like

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ASP.NET] 
"VerificationCompatibility"=dword:00000001 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP\Parameters] 
"AllowRestrictedChars"=dword:00000001
Tunis answered 5/4 at 2:45 Comment(2)
not sure who downvote your solution, but that did not work.Vindication
I've re-edited my answer, please try again.Tunis

© 2022 - 2024 — McMap. All rights reserved.