Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
86b6a4b6
Unverified
Commit
86b6a4b6
authored
Jul 15, 2019
by
JJ Kasper
Committed by
GitHub
Jul 15, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add handling for invalid page config (#7921)
parent
e7440858
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
0 deletions
+58
-0
invalid-page-config.md
errors/invalid-page-config.md
+26
-0
next-page-config.ts
packages/next/build/babel/plugins/next-page-config.ts
+12
-0
index.js
test/integration/page-config/pages/index.js
+2
-0
index.test.js
test/integration/page-config/test/index.test.js
+18
-0
No files found.
errors/invalid-page-config.md
0 → 100644
View file @
86b6a4b6
# 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
)
packages/next/build/babel/plugins/next-page-config.ts
View file @
86b6a4b6
...
@@ -60,6 +60,18 @@ export default function nextPageConfig({
...
@@ -60,6 +60,18 @@ export default function nextPageConfig({
for
(
const
declaration
of
declarations
)
{
for
(
const
declaration
of
declarations
)
{
if
(
declaration
.
id
.
name
!==
'config'
)
continue
if
(
declaration
.
id
.
name
!==
'config'
)
continue
if
(
declaration
.
init
.
type
!==
'ObjectExpression'
)
{
const
pageName
=
(
state
.
filename
||
''
).
split
(
state
.
cwd
||
''
).
pop
()
||
'unknown'
throw
new
Error
(
`Invalid page config export found. Expected object but got
${
declaration
.
init
.
type
}
in file
${
pageName
}
. See: https://err.sh/zeit/next.js/invalid-page-config`
)
}
for
(
const
prop
of
declaration
.
init
.
properties
)
{
for
(
const
prop
of
declaration
.
init
.
properties
)
{
const
{
name
}
=
prop
.
key
const
{
name
}
=
prop
.
key
if
(
configKeys
.
has
(
name
))
{
if
(
configKeys
.
has
(
name
))
{
...
...
test/integration/page-config/pages/index.js
View file @
86b6a4b6
import
{
config
as
hello
}
from
'../something'
import
{
config
as
hello
}
from
'../something'
import
{
config
as
world
}
from
'../config'
import
{
config
as
world
}
from
'../config'
// export const config = 'hello world'
export
default
()
=>
(
export
default
()
=>
(
<
p
>
<
p
>
{
hello
}
{
world
}
{
hello
}
{
world
}
...
...
test/integration/page-config/test/index.test.js
View file @
86b6a4b6
/* eslint-env jest */
/* eslint-env jest */
/* global jasmine */
/* global jasmine */
import
fs
from
'fs-extra'
import
{
join
}
from
'path'
import
{
join
}
from
'path'
import
{
nextBuild
}
from
'next-test-utils'
import
{
nextBuild
}
from
'next-test-utils'
const
appDir
=
join
(
__dirname
,
'..'
)
const
appDir
=
join
(
__dirname
,
'..'
)
const
indexPage
=
join
(
appDir
,
'pages/index.js'
)
jasmine
.
DEFAULT_TIMEOUT_INTERVAL
=
1000
*
60
*
2
jasmine
.
DEFAULT_TIMEOUT_INTERVAL
=
1000
*
60
*
2
describe
(
'Page Config'
,
()
=>
{
describe
(
'Page Config'
,
()
=>
{
...
@@ -11,4 +14,19 @@ describe('Page Config', () => {
...
@@ -11,4 +14,19 @@ describe('Page Config', () => {
const
{
stderr
}
=
await
nextBuild
(
appDir
,
undefined
,
{
stderr
:
true
})
const
{
stderr
}
=
await
nextBuild
(
appDir
,
undefined
,
{
stderr
:
true
})
expect
(
stderr
).
not
.
toMatch
(
/Failed to compile
\.
/
)
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'
)
}
})
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment