1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Handle pages with no default export and show an error. (#1484)

That error is meaningful and easy to find the issue.
This commit is contained in:
Arunoda Susiripala 2017-03-23 09:40:22 +05:30 committed by GitHub
parent bc2d5f3bdb
commit 97c472c0c8
3 changed files with 12 additions and 0 deletions

View file

@ -19,6 +19,11 @@ export default class App extends Component {
render () { render () {
const { Component, props, hash, err, router } = this.props const { Component, props, hash, err, router } = this.props
const url = createUrl(router) const url = createUrl(router)
// If there no component exported we can't proceed.
// We'll tackle that here.
if (typeof Component !== 'function') {
throw new Error(`The default export is not a React Component in page: "${url.pathname}"`)
}
const containerProps = { Component, props, hash, router, url } const containerProps = { Component, props, hash, router, url }
return <div> return <div>

View file

@ -0,0 +1 @@
export default {}

View file

@ -58,6 +58,12 @@ export default function ({ app }, suiteName, render) {
expect(html.includes('Zeit')).toBeTruthy() expect(html.includes('Zeit')).toBeTruthy()
}) })
test('default export is not a React Component', async () => {
const $ = await get$('/no-default-export')
const pre = $('pre')
expect(pre.text()).toMatch(/The default export is not a React Component/)
})
test('error', async () => { test('error', async () => {
const $ = await get$('/error') const $ = await get$('/error')
expect($('pre').text()).toMatch(/This is an expected error/) expect($('pre').text()).toMatch(/This is an expected error/)