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
e3fb62b6
Unverified
Commit
e3fb62b6
authored
Jun 27, 2022
by
JJ Kasper
Committed by
GitHub
Jun 27, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add invariant with debug information when failing to load static file (#38075)
parent
77f9a6a7
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
2 deletions
+53
-2
base-server.ts
packages/next/server/base-server.ts
+21
-0
require.ts
packages/next/server/require.ts
+4
-2
utils.ts
packages/next/shared/lib/utils.ts
+7
-0
required-server-files.test.ts
test/production/required-server-files.test.ts
+18
-0
auto-static.js
test/production/required-server-files/pages/auto-static.js
+3
-0
No files found.
packages/next/server/base-server.ts
View file @
e3fb62b6
...
@@ -22,6 +22,7 @@ import {
...
@@ -22,6 +22,7 @@ import {
NormalizeError
,
NormalizeError
,
DecodeError
,
DecodeError
,
normalizeRepeatedSlashes
,
normalizeRepeatedSlashes
,
MissingStaticPage
,
}
from
'../shared/lib/utils'
}
from
'../shared/lib/utils'
import
type
{
PreviewData
}
from
'next/types'
import
type
{
PreviewData
}
from
'next/types'
import
type
{
PagesManifest
}
from
'../build/webpack/plugins/pages-manifest-plugin'
import
type
{
PagesManifest
}
from
'../build/webpack/plugins/pages-manifest-plugin'
...
@@ -1856,6 +1857,26 @@ export default abstract class Server<ServerOptions extends Options = Options> {
...
@@ -1856,6 +1857,26 @@ export default abstract class Server<ServerOptions extends Options = Options> {
}
}
}
catch
(
error
)
{
}
catch
(
error
)
{
const
err
=
getProperError
(
error
)
const
err
=
getProperError
(
error
)
if
(
error
instanceof
MissingStaticPage
)
{
console
.
error
(
'Invariant: failed to load static page'
,
JSON
.
stringify
(
{
page
,
url
:
ctx
.
req
.
url
,
matchedPath
:
ctx
.
req
.
headers
[
'x-matched-path'
],
initUrl
:
getRequestMeta
(
ctx
.
req
,
'__NEXT_INIT_URL'
),
didRewrite
:
getRequestMeta
(
ctx
.
req
,
'_nextDidRewrite'
),
rewroteUrl
:
getRequestMeta
(
ctx
.
req
,
'_nextRewroteUrl'
),
},
null
,
2
)
)
throw
err
}
if
(
err
instanceof
NoFallbackError
&&
bubbleNoFallback
)
{
if
(
err
instanceof
NoFallbackError
&&
bubbleNoFallback
)
{
throw
err
throw
err
}
}
...
...
packages/next/server/require.ts
View file @
e3fb62b6
...
@@ -11,7 +11,7 @@ import { normalizeLocalePath } from '../shared/lib/i18n/normalize-locale-path'
...
@@ -11,7 +11,7 @@ import { normalizeLocalePath } from '../shared/lib/i18n/normalize-locale-path'
import
{
normalizePagePath
}
from
'../shared/lib/page-path/normalize-page-path'
import
{
normalizePagePath
}
from
'../shared/lib/page-path/normalize-page-path'
import
{
denormalizePagePath
}
from
'../shared/lib/page-path/denormalize-page-path'
import
{
denormalizePagePath
}
from
'../shared/lib/page-path/denormalize-page-path'
import
type
{
PagesManifest
}
from
'../build/webpack/plugins/pages-manifest-plugin'
import
type
{
PagesManifest
}
from
'../build/webpack/plugins/pages-manifest-plugin'
import
{
PageNotFoundError
}
from
'../shared/lib/utils'
import
{
PageNotFoundError
,
MissingStaticPage
}
from
'../shared/lib/utils'
export
function
getPagePath
(
export
function
getPagePath
(
page
:
string
,
page
:
string
,
...
@@ -90,7 +90,9 @@ export function requirePage(
...
@@ -90,7 +90,9 @@ export function requirePage(
appDirEnabled
appDirEnabled
)
)
if
(
pagePath
.
endsWith
(
'.html'
))
{
if
(
pagePath
.
endsWith
(
'.html'
))
{
return
promises
.
readFile
(
pagePath
,
'utf8'
)
return
promises
.
readFile
(
pagePath
,
'utf8'
).
catch
((
err
)
=>
{
throw
new
MissingStaticPage
(
page
,
err
.
message
)
})
}
}
return
require
(
pagePath
)
return
require
(
pagePath
)
}
}
...
...
packages/next/shared/lib/utils.ts
View file @
e3fb62b6
...
@@ -413,6 +413,13 @@ export class PageNotFoundError extends Error {
...
@@ -413,6 +413,13 @@ export class PageNotFoundError extends Error {
}
}
}
}
export
class
MissingStaticPage
extends
Error
{
constructor
(
page
:
string
,
message
:
string
)
{
super
()
this
.
message
=
`Failed to load static file for page:
${
page
}
${
message
}
`
}
}
export
class
MiddlewareNotFoundError
extends
Error
{
export
class
MiddlewareNotFoundError
extends
Error
{
code
:
string
code
:
string
constructor
()
{
constructor
()
{
...
...
test/production/required-server-files.test.ts
View file @
e3fb62b6
...
@@ -138,6 +138,24 @@ describe('should set-up next', () => {
...
@@ -138,6 +138,24 @@ describe('should set-up next', () => {
if
(
server
)
await
killApp
(
server
)
if
(
server
)
await
killApp
(
server
)
})
})
it
(
'should show invariant when an automatic static page is requested'
,
async
()
=>
{
const
toRename
=
`standalone/.next/server/pages/auto-static.html`
await
next
.
renameFile
(
toRename
,
`
${
toRename
}
.bak`
)
try
{
const
res
=
await
fetchViaHTTP
(
appPort
,
'/auto-static'
,
undefined
,
{
headers
:
{
'x-matched-path'
:
'/auto-static'
,
},
})
expect
(
res
.
status
).
toBe
(
500
)
await
check
(()
=>
stderr
,
/Invariant: failed to load static page/
)
}
finally
{
await
next
.
renameFile
(
`
${
toRename
}
.bak`
,
toRename
)
}
})
it
.
each
([
it
.
each
([
{
{
case
:
'redirect no revalidate'
,
case
:
'redirect no revalidate'
,
...
...
test/production/required-server-files/pages/auto-static.js
0 → 100644
View file @
e3fb62b6
export
default
function
Page
()
{
return
<
p
>
automatic
static
page
<
/p
>
}
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