Skip to content

Commit 97c472c

Browse files
authored
Handle pages with no default export and show an error. (vercel#1484)
That error is meaningful and easy to find the issue.
1 parent bc2d5f3 commit 97c472c

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

lib/app.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ export default class App extends Component {
1919
render () {
2020
const { Component, props, hash, err, router } = this.props
2121
const url = createUrl(router)
22+
// If there no component exported we can't proceed.
23+
// We'll tackle that here.
24+
if (typeof Component !== 'function') {
25+
throw new Error(`The default export is not a React Component in page: "${url.pathname}"`)
26+
}
2227
const containerProps = { Component, props, hash, router, url }
2328

2429
return <div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default {}

test/integration/basic/test/rendering.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ export default function ({ app }, suiteName, render) {
5858
expect(html.includes('Zeit')).toBeTruthy()
5959
})
6060

61+
test('default export is not a React Component', async () => {
62+
const $ = await get$('/no-default-export')
63+
const pre = $('pre')
64+
expect(pre.text()).toMatch(/The default export is not a React Component/)
65+
})
66+
6167
test('error', async () => {
6268
const $ = await get$('/error')
6369
expect($('pre').text()).toMatch(/This is an expected error/)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy