diff --git a/packages/next/pages/_document.tsx b/packages/next/pages/_document.tsx
index 7d3259af7475df..989efe682e8a49 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/app.css b/test/integration/document-file-dependencies/css/app.css
new file mode 100644
index 00000000000000..bcb11204cd0857
--- /dev/null
+++ b/test/integration/document-file-dependencies/css/app.css
@@ -0,0 +1,3 @@
+.global {
+ background-color: #eeeeee;
+}
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 00000000000000..efdfa20ef94715
--- /dev/null
+++ b/test/integration/document-file-dependencies/css/error.module.css
@@ -0,0 +1,3 @@
+.error {
+ color: #ff0000;
+}
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 00000000000000..2534e4c6b0115e
--- /dev/null
+++ b/test/integration/document-file-dependencies/css/index.module.css
@@ -0,0 +1,3 @@
+.index {
+ color: #333333;
+}
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 00000000000000..fab489588a00c9
--- /dev/null
+++ b/test/integration/document-file-dependencies/pages/_app.js
@@ -0,0 +1,11 @@
+import '../css/app.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 00000000000000..3ea8ea1bd0f58e
--- /dev/null
+++ b/test/integration/document-file-dependencies/pages/_error.js
@@ -0,0 +1,5 @@
+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 00000000000000..6888cac20b1d3a
--- /dev/null
+++ b/test/integration/document-file-dependencies/pages/error-trigger.js
@@ -0,0 +1,14 @@
+import style from '../css/index.module.css'
+
+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 00000000000000..be138891666b89
--- /dev/null
+++ b/test/integration/document-file-dependencies/pages/index.js
@@ -0,0 +1,5 @@
+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 00000000000000..19f60c6695bd8e
--- /dev/null
+++ b/test/integration/document-file-dependencies/test/index.test.js
@@ -0,0 +1,50 @@
+/* eslint-env jest */
+
+import { join } from 'path'
+import {
+ fetchViaHTTP,
+ findPort,
+ killApp,
+ nextBuild,
+ nextStart,
+} from 'next-test-utils'
+import cheerio from 'cheerio'
+
+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 depend on global and module css files in standard page', async () => {
+ const res = await fetchViaHTTP(appPort, '/')
+ const $ = cheerio.load(await res.text())
+ const cssFiles = $('link[rel="stylesheet"]')
+ expect(cssFiles.length).toBe(2)
+ })
+
+ it('should depend on global and module css files in 404 page', async () => {
+ const res = await fetchViaHTTP(appPort, '/__not_found__')
+ const $ = cheerio.load(await res.text())
+ const cssFiles = $('link[rel="stylesheet"]')
+ expect(cssFiles.length).toBe(2)
+ })
+
+ it('should depend on global and module css files in _error page', async () => {
+ const res = await fetchViaHTTP(appPort, '/error-trigger')
+ const $ = cheerio.load(await res.text())
+ const cssFiles = $('link[rel="stylesheet"]')
+ expect(cssFiles.length).toBe(2)
+ })
+ })
+})