Skip to content

Commit c63dbb8

Browse files
piehfreiksenet
authored andcommitted
fix(develop): fix "Unexpected token < in JSON at position 0" after restarting development server (#14166)
1 parent deb6652 commit c63dbb8

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

packages/gatsby/src/commands/develop.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,14 @@ async function startServer(program) {
220220

221221
await apiRunnerNode(`onCreateDevServer`, { app })
222222

223+
// In case nothing before handled hot-update - send 404.
224+
// This fixes "Unexpected token < in JSON at position 0" runtime
225+
// errors after restarting development server and
226+
// cause automatic hard refresh in the browser.
227+
app.use(/.*\.hot-update\.json$/i, (req, res) => {
228+
res.status(404).end()
229+
})
230+
223231
// Render an HTML page and serve it.
224232
app.use((req, res, next) => {
225233
res.sendFile(directoryPath(`public/index.html`), err => {

0 commit comments

Comments
 (0)