Skip to content

Commit d5f9331

Browse files
committed
fix(build,dev): respect NODE_PATH when loading kit/nuxt
#1090
1 parent 9b61096 commit d5f9331

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

packages/nuxi/src/dev/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import { joinURL } from 'ufo'
2525
import { showVersionsFromConfig } from '../utils/banner'
2626
import { clearBuildDir } from '../utils/fs'
2727
import { loadKit } from '../utils/kit'
28-
2928
import { loadNuxtManifest, resolveNuxtManifest, writeNuxtManifest } from '../utils/nuxt'
29+
import { withNodePath } from '../utils/paths'
3030
import { renderError } from './error'
3131

3232
export type NuxtParentIPCMessage
@@ -561,8 +561,8 @@ function createConfigDirWatcher(cwd: string, onReload: (file: string) => void) {
561561

562562
// Nuxt <3.6 did not have the loading template defined in the schema
563563
async function resolveLoadingTemplate(cwd: string): Promise<({ loading }: { loading?: string }) => string> {
564-
const nuxtPath = resolveModulePath('nuxt', { from: cwd, try: true })
565-
const uiTemplatesPath = resolveModulePath('@nuxt/ui-templates', { from: nuxtPath || cwd })
564+
const nuxtPath = resolveModulePath('nuxt', { from: withNodePath(cwd), try: true })
565+
const uiTemplatesPath = resolveModulePath('@nuxt/ui-templates', { from: withNodePath(nuxtPath || cwd) })
566566
const r: { loading: (opts?: { loading?: string }) => string } = await import(pathToFileURL(uiTemplatesPath).href)
567567

568568
return r.loading || ((params: { loading: string }) => `<h2>${params.loading}</h2>`)

packages/nuxi/src/utils/kit.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { pathToFileURL } from 'node:url'
22
import { resolveModulePath } from 'exsolve'
3+
import { withNodePath } from './paths'
34

45
export async function loadKit(rootDir: string): Promise<typeof import('@nuxt/kit')> {
56
try {
@@ -28,7 +29,7 @@ export async function loadKit(rootDir: string): Promise<typeof import('@nuxt/kit
2829

2930
export function tryResolveNuxt(rootDir: string) {
3031
for (const pkg of ['nuxt-nightly', 'nuxt', 'nuxt3', 'nuxt-edge']) {
31-
const path = resolveModulePath(pkg, { from: rootDir, try: true })
32+
const path = resolveModulePath(pkg, { from: withNodePath(rootDir), try: true })
3233
if (path) {
3334
return path
3435
}

packages/nuxi/src/utils/paths.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ const cwd = process.cwd()
66
export function relativeToProcess(path: string) {
77
return relative(cwd, path) || path
88
}
9+
10+
export function withNodePath(path: string) {
11+
return [path, process.env.NODE_PATH].filter((i): i is NonNullable<typeof i> => !!i)
12+
}

0 commit comments

Comments
 (0)