diff --git a/lib/builder/builder.js b/lib/builder/builder.js
index d8e2835a01..d531c22026 100644
--- a/lib/builder/builder.js
+++ b/lib/builder/builder.js
@@ -223,7 +223,6 @@ export default class Builder {
cwd: this.options.srcDir,
ignore: this.options.ignore
})
- let hasErrorLayout = false
layoutsFiles.forEach((file) => {
const name = file
.split('/')
@@ -231,7 +230,12 @@ export default class Builder {
.join('/')
.replace(/\.(vue|js)$/, '')
if (name === 'error') {
- hasErrorLayout = true
+ if (!templateVars.components.ErrorPage) {
+ templateVars.components.ErrorPage = this.relativeToBuild(
+ this.options.srcDir,
+ file
+ )
+ }
return
}
if (!templateVars.layouts[name] || /\.vue$/.test(file)) {
@@ -241,12 +245,6 @@ export default class Builder {
)
}
})
- if (!templateVars.components.ErrorPage && hasErrorLayout) {
- templateVars.components.ErrorPage = this.relativeToBuild(
- this.options.srcDir,
- `${this.options.dir.layouts}/error.vue`
- )
- }
}
// If no default layout, create its folder and add the default folder
if (!templateVars.layouts.default) {
diff --git a/lib/core/module.js b/lib/core/module.js
index 5446cbae16..7d90614c63 100644
--- a/lib/core/module.js
+++ b/lib/core/module.js
@@ -71,6 +71,16 @@ export default class ModuleContainer {
// Add to nuxt layouts
this.options.layouts[name || path.parse(src).name] = `./${dst}`
+
+ // If error layout, set ErrorPage
+ if (name === 'error') {
+ this.addErrorLayout(dst)
+ }
+ }
+
+ addErrorLayout(dst) {
+ const relativeBuildDir = path.relative(this.options.rootDir, this.options.buildDir)
+ this.options.ErrorPage = `~/${relativeBuildDir}/${dst}`
}
addServerMiddleware(middleware) {
diff --git a/test/fixtures/module/modules/layout/index.js b/test/fixtures/module/modules/layout/index.js
new file mode 100644
index 0000000000..ae6b982f8d
--- /dev/null
+++ b/test/fixtures/module/modules/layout/index.js
@@ -0,0 +1,6 @@
+import { resolve } from 'path'
+
+export default function module() {
+ this.addLayout(
+ { src: resolve(__dirname, 'some-error.vue') }, 'error')
+}
diff --git a/test/fixtures/module/modules/layout/some-error.vue b/test/fixtures/module/modules/layout/some-error.vue
new file mode 100644
index 0000000000..e11cbe3f28
--- /dev/null
+++ b/test/fixtures/module/modules/layout/some-error.vue
@@ -0,0 +1,3 @@
+
+ You should see the error in a different Vue!
+
diff --git a/test/fixtures/module/nuxt.config.js b/test/fixtures/module/nuxt.config.js
index 07f5ab6e5a..cf3ef40c88 100644
--- a/test/fixtures/module/nuxt.config.js
+++ b/test/fixtures/module/nuxt.config.js
@@ -3,6 +3,7 @@ export default {
modules: [
'~~/modules/basic',
'~/modules/hooks',
+ '~/modules/layout',
{
src: '~/modules/middleware',
options: {
diff --git a/test/unit/module.test.js b/test/unit/module.test.js
index d579ad58b9..f53ff3859a 100644
--- a/test/unit/module.test.js
+++ b/test/unit/module.test.js
@@ -31,6 +31,11 @@ describe('module', () => {
expect(html.includes('