mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
fix(nuxi): resolve kit from nuxt modules dir (#19601)
This commit is contained in:
parent
4de4de1a71
commit
3684de58f4
@ -1,12 +1,24 @@
|
||||
import { importModule } from './esm'
|
||||
import { importModule, tryResolveModule } from './esm'
|
||||
|
||||
export const loadKit = async (rootDir: string): Promise<typeof import('@nuxt/kit')> => {
|
||||
try {
|
||||
return await importModule('@nuxt/kit', rootDir) as typeof import('@nuxt/kit')
|
||||
// Without PNP (or if users have a local install of kit, we bypass resolving from nuxt)
|
||||
const localKit = await tryResolveModule('@nuxt/kit', rootDir)
|
||||
// Otherwise, we resolve Nuxt _first_ as it is Nuxt's kit dependency that will be used
|
||||
const rootURL = localKit ? rootDir : await tryResolveNuxt() || rootDir
|
||||
return await importModule('@nuxt/kit', rootURL) as typeof import('@nuxt/kit')
|
||||
} catch (e: any) {
|
||||
if (e.toString().includes("Cannot find module '@nuxt/kit'")) {
|
||||
throw new Error('nuxi requires `@nuxt/kit` to be installed in your project. Try installing `nuxt3` or `@nuxt/bridge` first.')
|
||||
throw new Error('nuxi requires `@nuxt/kit` to be installed in your project. Try installing `nuxt` v3 or `@nuxt/bridge` first.')
|
||||
}
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
async function tryResolveNuxt () {
|
||||
for (const pkg of ['nuxt3', 'nuxt', 'nuxt-edge']) {
|
||||
const path = await tryResolveModule(pkg)
|
||||
if (path) { return path }
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user