diff --git a/packages/next/pages/_document.tsx b/packages/next/pages/_document.tsx
index 715d5b136bc40eac72907488b3ac40a2b16dc532..0b129671e54a46f931d1ef6e4c073902358cbdc8 100644
--- a/packages/next/pages/_document.tsx
+++ b/packages/next/pages/_document.tsx
@@ -55,8 +55,7 @@ function getDocumentFiles(
pathname: string
): DocumentFiles {
const sharedFiles: readonly string[] = getPageFiles(buildManifest, '/_app')
- const pageFiles: readonly string[] =
- pathname !== '/_error' ? getPageFiles(buildManifest, pathname) : []
+ const pageFiles: readonly string[] = getPageFiles(buildManifest, pathname)
return {
sharedFiles,
diff --git a/test/integration/document-file-dependencies/css/404.module.css b/test/integration/document-file-dependencies/css/404.module.css
new file mode 100644
index 0000000000000000000000000000000000000000..8d3ceabecbc87ed9901d6343529a369026ee2bd3
--- /dev/null
+++ b/test/integration/document-file-dependencies/css/404.module.css
@@ -0,0 +1,3 @@
+.notFound {
+ color: rgb(0, 255, 0);
+}
diff --git a/test/integration/document-file-dependencies/css/error.module.css b/test/integration/document-file-dependencies/css/error.module.css
new file mode 100644
index 0000000000000000000000000000000000000000..bb42fe16ec65e2e7a1390b7fdaf8480edd6c25f4
--- /dev/null
+++ b/test/integration/document-file-dependencies/css/error.module.css
@@ -0,0 +1,3 @@
+.error {
+ color: rgb(255, 0, 0);
+}
diff --git a/test/integration/document-file-dependencies/css/global.css b/test/integration/document-file-dependencies/css/global.css
new file mode 100644
index 0000000000000000000000000000000000000000..685ca2f87fd4f292ca7a0ca505579c1412c406ac
--- /dev/null
+++ b/test/integration/document-file-dependencies/css/global.css
@@ -0,0 +1,3 @@
+.global {
+ background-color: rgb(200, 200, 200);
+}
diff --git a/test/integration/document-file-dependencies/css/index.module.css b/test/integration/document-file-dependencies/css/index.module.css
new file mode 100644
index 0000000000000000000000000000000000000000..ad8af317efe885ba76dc1ee6ab4410687d59043e
--- /dev/null
+++ b/test/integration/document-file-dependencies/css/index.module.css
@@ -0,0 +1,3 @@
+.index {
+ color: rgb(0, 0, 255);
+}
diff --git a/test/integration/document-file-dependencies/pages/404.js b/test/integration/document-file-dependencies/pages/404.js
new file mode 100644
index 0000000000000000000000000000000000000000..0286b47bcbc60e1f6beeaf8505bf787daca99b64
--- /dev/null
+++ b/test/integration/document-file-dependencies/pages/404.js
@@ -0,0 +1,9 @@
+import style from '../css/404.module.css'
+
+export default function NotFound() {
+ return (
+
+ error
+
+ )
+}
diff --git a/test/integration/document-file-dependencies/pages/_app.js b/test/integration/document-file-dependencies/pages/_app.js
new file mode 100644
index 0000000000000000000000000000000000000000..c9dc58476d508627ba226f72bf03ca94b8b1e4e8
--- /dev/null
+++ b/test/integration/document-file-dependencies/pages/_app.js
@@ -0,0 +1,7 @@
+import '../css/global.css'
+
+function App({ Component, pageProps }) {
+ return
+}
+
+export default App
diff --git a/test/integration/document-file-dependencies/pages/_error.js b/test/integration/document-file-dependencies/pages/_error.js
new file mode 100644
index 0000000000000000000000000000000000000000..0263d4a3daa81ff679370a41f77e2e902555f853
--- /dev/null
+++ b/test/integration/document-file-dependencies/pages/_error.js
@@ -0,0 +1,9 @@
+import style from '../css/error.module.css'
+
+export default function Error() {
+ return (
+
+ error
+
+ )
+}
diff --git a/test/integration/document-file-dependencies/pages/error-trigger.js b/test/integration/document-file-dependencies/pages/error-trigger.js
new file mode 100644
index 0000000000000000000000000000000000000000..955dbf1988dde62150e769191e230c0d956d0c8d
--- /dev/null
+++ b/test/integration/document-file-dependencies/pages/error-trigger.js
@@ -0,0 +1,12 @@
+function ErrorTrigger() {
+ return error-trigger
+}
+
+ErrorTrigger.getInitialProps = () => {
+ throw new Error('Intentional Error')
+
+ // eslint-disable-next-line no-unreachable
+ return {}
+}
+
+export default ErrorTrigger
diff --git a/test/integration/document-file-dependencies/pages/index.js b/test/integration/document-file-dependencies/pages/index.js
new file mode 100644
index 0000000000000000000000000000000000000000..c129b2c57ef99d836e2d8da604bcc156720291e9
--- /dev/null
+++ b/test/integration/document-file-dependencies/pages/index.js
@@ -0,0 +1,9 @@
+import style from '../css/index.module.css'
+
+export default function Index() {
+ return (
+
+ index
+
+ )
+}
diff --git a/test/integration/document-file-dependencies/test/index.test.js b/test/integration/document-file-dependencies/test/index.test.js
new file mode 100644
index 0000000000000000000000000000000000000000..ed943a2204167ddc2f2ba392ed090b5bf97f580c
--- /dev/null
+++ b/test/integration/document-file-dependencies/test/index.test.js
@@ -0,0 +1,77 @@
+/* eslint-env jest */
+
+import { join } from 'path'
+import { findPort, killApp, nextBuild, nextStart } from 'next-test-utils'
+import webdriver from 'next-webdriver'
+
+jest.setTimeout(1000 * 60 * 2)
+const appDir = join(__dirname, '..')
+
+let appPort
+let app
+
+describe('File Dependencies', () => {
+ describe('production mode', () => {
+ beforeAll(async () => {
+ appPort = await findPort()
+ await nextBuild(appDir)
+ app = await nextStart(appDir, appPort)
+ })
+
+ afterAll(() => killApp(app))
+
+ it('should apply styles defined in global and module css files in a standard page.', async () => {
+ const browser = await webdriver(appPort, '/')
+ await browser.waitForElementByCss('#index')
+
+ const styles = await browser.eval(() => {
+ const computed = getComputedStyle(document.getElementById('index'))
+ return {
+ color: computed.color,
+ backgroundColor: computed.backgroundColor,
+ }
+ })
+
+ expect(styles).toEqual({
+ color: 'rgb(0, 0, 255)',
+ backgroundColor: 'rgb(200, 200, 200)',
+ })
+ })
+
+ it('should apply styles defined in global and module css files in 404 page', async () => {
+ const browser = await webdriver(appPort, '/__not_found__')
+ await browser.waitForElementByCss('#notFound')
+
+ const styles = await browser.eval(() => {
+ const computed = getComputedStyle(document.getElementById('notFound'))
+ return {
+ color: computed.color,
+ backgroundColor: computed.backgroundColor,
+ }
+ })
+
+ expect(styles).toEqual({
+ color: 'rgb(0, 255, 0)',
+ backgroundColor: 'rgb(200, 200, 200)',
+ })
+ })
+
+ it('should apply styles defined in global and module css files in error page', async () => {
+ const browser = await webdriver(appPort, '/error-trigger')
+ await browser.waitForElementByCss('#error')
+
+ const styles = await browser.eval(() => {
+ const computed = getComputedStyle(document.getElementById('error'))
+ return {
+ color: computed.color,
+ backgroundColor: computed.backgroundColor,
+ }
+ })
+
+ expect(styles).toEqual({
+ color: 'rgb(255, 0, 0)',
+ backgroundColor: 'rgb(200, 200, 200)',
+ })
+ })
+ })
+})