Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add handling for invalid pages during autoExport (#7574)
* Add handling for invalid pages during autoExport * Add err.sh link for invalid page export * Fix typo * Apply suggestions from code review Co-Authored-By: Tim Neutkens <tim@timneutkens.nl>
- Loading branch information
1 parent
feb31f4
commit 090a06b
Showing
9 changed files
with
74 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Page Without Valid React Component | ||
|
||
#### Why This Error Occurred | ||
|
||
While auto exporting a page a valid React Component wasn't found. This could mean you have a file in `pages` that exports something that is not a React Component. | ||
|
||
#### Possible Ways to Fix It | ||
|
||
Move any non-page files that don't export a React Component as the default export to a different folder like `components` or `lib`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
experimental: { | ||
autoExport: true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'just a string' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React, { Component } from 'react' | ||
|
||
export default class AlsoValid extends Component { | ||
render () { | ||
return <div>Hi there</div> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const obj = { | ||
something: 'idk' | ||
} | ||
|
||
export default obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default () => <p>Hello world</p> |
19 changes: 19 additions & 0 deletions
19
test/integration/invalid-page-autoExport/test/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* eslint-env jest */ | ||
/* global jasmine, test */ | ||
import path from 'path' | ||
import { nextBuild } from 'next-test-utils' | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2 | ||
const appDir = path.join(__dirname, '..') | ||
|
||
describe('Invalid Page autoExport', () => { | ||
it('Fails softly with descriptive error', async () => { | ||
const { stderr } = await nextBuild(appDir, [], { stderr: true }) | ||
|
||
expect(stderr).toMatch( | ||
/autoExport failed: found pages without React Component as default export/ | ||
) | ||
expect(stderr).toMatch(/pages\/invalid/) | ||
expect(stderr).toMatch(/pages\/also-invalid/) | ||
}) | ||
}) |