Skip to content

Netlify Dev incorrectly rewrites requests for files that *don't* exist #753

@edaemon

Description

@edaemon

I think this is the right place to open this; https://github.com/netlify/netlify-dev-plugin/issues/155 and https://github.com/netlify/netlify-dev-plugin/issues/181 seem related but don't quite capture the issue.

There seems to be a difference in the way netlify dev processes redirects compared to the Netlify platform. (Note: I'm not certain both/either use node-redirects-parser, just assuming.) In a CRA app using react-router, you need a public/_redirects file like this to use any routes aside from the base path:

/*    /index.html    200

That works fine on Netlify itself; requests to custom routes are properly rewritten without interfering with requests for files that actually exist. However netlify dev seemingly applies this rule to all requests, similar to the way Netlify would if you appended an exclamation point to the rewrite (200!). This means requests for scripts like /static/js/bundle.js and other basic assets are rewritten to /index.html. The rewritten requests get a 200 response but obviously it serves the HTML, so JS processing will immediately throw errors like Uncaught SyntaxError: Unexpected token <.

This breaks Netlify Dev, which has otherwise been immensely useful; I'm searching for a workaround/fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions