forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
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 page config (vercel#7921)
- Loading branch information
Showing
4 changed files
with
58 additions
and
0 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,26 @@ | ||
# Invalid Page Config | ||
|
||
#### Why This Error Occurred | ||
|
||
In one of your pages you did `export const config` with an invalid value. | ||
|
||
#### Possible Ways to Fix It | ||
|
||
The page's config must be an object initialized directly when being exported. | ||
|
||
This is not allowed | ||
|
||
```js | ||
export const config = 'hello world' | ||
``` | ||
|
||
This is allowed | ||
|
||
```js | ||
export const config = { amp: true } | ||
``` | ||
|
||
### Useful Links | ||
|
||
- [Enabling AMP Support](https://github.com/zeit/next.js/#enabling-amp-support) | ||
- [API Middlewares](https://github.com/zeit/next.js/#api-middlewares) |
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 |
---|---|---|
@@ -1,14 +1,32 @@ | ||
/* eslint-env jest */ | ||
/* global jasmine */ | ||
import fs from 'fs-extra' | ||
import { join } from 'path' | ||
import { nextBuild } from 'next-test-utils' | ||
|
||
const appDir = join(__dirname, '..') | ||
const indexPage = join(appDir, 'pages/index.js') | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2 | ||
|
||
describe('Page Config', () => { | ||
it('builds without error when export const config is used outside page', async () => { | ||
const { stderr } = await nextBuild(appDir, undefined, { stderr: true }) | ||
expect(stderr).not.toMatch(/Failed to compile\./) | ||
}) | ||
|
||
it('shows valid error on invalid page config', async () => { | ||
const origContent = await fs.readFile(indexPage, 'utf8') | ||
const newContent = origContent.replace('// export', 'export') | ||
await fs.writeFile(indexPage, newContent, 'utf8') | ||
|
||
try { | ||
const { stderr } = await nextBuild(appDir, undefined, { stderr: true }) | ||
expect(stderr).toMatch( | ||
/https:\/\/err\.sh\/zeit\/next\.js\/invalid-page-config/ | ||
) | ||
} finally { | ||
await fs.writeFile(indexPage, origContent, 'utf8') | ||
} | ||
}) | ||
}) |