Next.js: Static Assets Return 404 After Setting basePath
The application in the subdirectory /panel opens HTML, but styles and JavaScript are loaded from invalid paths. BasePath and assetPrefix configuration may not match reverse proxy or target subdirectory.
How to identify the source of the problem
Find missing resources in the Network next and save their full URLs. Compare basePath in next.config with proxy rules and the actual path under which the project is served.
Compare the message from the console with the result of the production compilation and the condition after the page has been refreshed.
Repair steps
Unify basePath with proxy and correct the reference to public resources that are not automatically prefixed. Rebuild the project after changing basePath, as the setting is built into the client code during build.
How to Test Solution
HTML, CSS and JS load from the same prefix on production.
Security and restrictions
Do not try to repair each resource by a separate redirect when the entire prefix is bad.