Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add error when attempting to export GSSP page (#11154)
* Add error when attempting to export GSSP page * Update errors/gssp-export.md * Update errors/gssp-export.md * Update errors/gssp-export.md Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
- Loading branch information
1 parent
408a01c
commit 203f43c
Showing
6 changed files
with
97 additions
and
37 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,14 @@ | ||
# getServerSideProps Export Error | ||
|
||
#### Why This Error Occurred | ||
|
||
You attempted to export a page with `getServerSideProps` which is not allowed. `getServerSideProps` is meant for requesting up to date information on every request which means exporting it defeats the purpose of the method. | ||
|
||
#### Possible Ways to Fix It | ||
|
||
If you would like the page be static you can leverage the `getStaticProps` method instead. | ||
|
||
### Useful Links | ||
|
||
- [`getStaticProps` documentation](https://nextjs.org/docs/basic-features/data-fetching#getstaticprops-static-generation) | ||
- [`exportPathMap` documentation](https://nextjs.org/docs/api-reference/next.config.js/exportPathMap) |
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
9 changes: 9 additions & 0 deletions
9
test/integration/getserversideprops-export-error/pages/index.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,9 @@ | ||
export async function getServerSideProps() { | ||
return { | ||
props: { | ||
idk: 'oops', | ||
}, | ||
} | ||
} | ||
|
||
export default () => 'hi' |
54 changes: 54 additions & 0 deletions
54
test/integration/getserversideprops-export-error/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,54 @@ | ||
/* eslint-env jest */ | ||
/* global jasmine */ | ||
import fs from 'fs-extra' | ||
import { nextBuild, nextExport } from 'next-test-utils' | ||
import { join } from 'path' | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2 | ||
const appDir = join(__dirname, '..') | ||
const nextConfig = join(appDir, 'next.config.js') | ||
|
||
const runTests = () => { | ||
it('should build successfully', async () => { | ||
const { stdout, code } = await nextBuild(appDir, [], { stdout: true }) | ||
expect(code).toBe(0) | ||
expect(stdout).toMatch(/Compiled successfully/) | ||
}) | ||
|
||
it('should show error for GSSP during export', async () => { | ||
const { stderr, code } = await nextExport( | ||
appDir, | ||
{ outdir: join(appDir, 'out') }, | ||
{ stderr: true } | ||
) | ||
|
||
expect(code).toBe(1) | ||
expect(stderr).toMatch( | ||
/pages with `getServerSideProps` can not be exported. See more info here: https/ | ||
) | ||
}) | ||
} | ||
|
||
describe('getServerSideProps', () => { | ||
describe('serverless mode', () => { | ||
beforeAll(async () => { | ||
await fs.remove(join(appDir, '.next')) | ||
await fs.writeFile( | ||
nextConfig, | ||
`module.exports = { target: 'experimental-serverless-trace' }`, | ||
'utf8' | ||
) | ||
}) | ||
|
||
runTests() | ||
}) | ||
|
||
describe('production mode', () => { | ||
beforeAll(async () => { | ||
await fs.remove(nextConfig) | ||
await fs.remove(join(appDir, '.next')) | ||
}) | ||
|
||
runTests() | ||
}) | ||
}) |
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