From 72a9beff6451751c87baebdfc0bc27a61f3d5888 Mon Sep 17 00:00:00 2001 From: Hana Shiro Date: Sat, 22 Jul 2017 20:30:31 +0800 Subject: [PATCH] Resolve requires from `rootDir` --- lib/core/nuxt.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/core/nuxt.js b/lib/core/nuxt.js index 9e56920d85..92d103e997 100644 --- a/lib/core/nuxt.js +++ b/lib/core/nuxt.js @@ -5,6 +5,7 @@ import Renderer from './renderer' import Options from './options' import Debug from 'debug' import enableDestroy from 'server-destroy' +import Module from 'module' import { join, resolve } from 'path' const debug = Debug('nuxt:') @@ -16,6 +17,8 @@ export default class Nuxt extends Tapable { this.options = Options(_options) + // Paths for resolving requires from `rootDir` + this.nodeModulePaths = Module._nodeModulePaths(this.options.rootDir) this.initialized = false this.errorHandler = this.errorHandler.bind(this) @@ -102,7 +105,7 @@ export default class Nuxt extends Tapable { resolvePath (path) { // Try to resolve using NPM resolve path first try { - let resolvedPath = require.resolve(path) + let resolvedPath = Module._resolveFilename(path, { paths: this.nodeModulePaths }) return resolvedPath } catch (e) { // Just continue