mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 17:35:57 +00:00
fix(nuxi): warn if user does not have @nuxt/kit
installed (#915)
This commit is contained in:
parent
cb983103cb
commit
f0ce5f78f8
@ -1,8 +1,8 @@
|
||||
import { resolve } from 'pathe'
|
||||
import consola from 'consola'
|
||||
import { importModule } from '../utils/cjs'
|
||||
|
||||
import { writeTypes } from '../utils/prepare'
|
||||
import { loadKit } from '../utils/kit'
|
||||
import { defineNuxtCommand } from './index'
|
||||
|
||||
export default defineNuxtCommand({
|
||||
@ -15,7 +15,7 @@ export default defineNuxtCommand({
|
||||
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
|
||||
const rootDir = resolve(args._[0] || '.')
|
||||
|
||||
const { loadNuxt, buildNuxt } = await importModule('@nuxt/kit', rootDir) as typeof import('@nuxt/kit')
|
||||
const { loadNuxt, buildNuxt } = await loadKit(rootDir)
|
||||
|
||||
const nuxt = await loadNuxt({ rootDir })
|
||||
|
||||
|
@ -5,8 +5,8 @@ import type { Nuxt } from '@nuxt/kit'
|
||||
import consola from 'consola'
|
||||
import { createServer, createLoadingHandler } from '../utils/server'
|
||||
import { showBanner } from '../utils/banner'
|
||||
import { importModule } from '../utils/cjs'
|
||||
import { writeTypes } from '../utils/prepare'
|
||||
import { loadKit } from '../utils/kit'
|
||||
import { defineNuxtCommand } from './index'
|
||||
|
||||
export default defineNuxtCommand({
|
||||
@ -26,7 +26,7 @@ export default defineNuxtCommand({
|
||||
|
||||
const rootDir = resolve(args._[0] || '.')
|
||||
|
||||
const { loadNuxt, buildNuxt } = await importModule('@nuxt/kit', rootDir) as typeof import('@nuxt/kit')
|
||||
const { loadNuxt, buildNuxt } = await loadKit(rootDir)
|
||||
|
||||
const prepare = debounce(nuxt => writeTypes(nuxt), 1000)
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { resolve } from 'pathe'
|
||||
import { isNuxt3 } from '@nuxt/kit'
|
||||
import { importModule } from '../utils/cjs'
|
||||
|
||||
import { loadKit } from '../utils/kit'
|
||||
import { defineNuxtCommand } from './index'
|
||||
|
||||
export default defineNuxtCommand({
|
||||
@ -14,7 +14,7 @@ export default defineNuxtCommand({
|
||||
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
|
||||
const rootDir = resolve(args._[0] || '.')
|
||||
|
||||
const { loadNuxt } = await importModule('@nuxt/kit', rootDir) as typeof import('@nuxt/kit')
|
||||
const { loadNuxt } = await loadKit(rootDir)
|
||||
const nuxt = await loadNuxt({ rootDir })
|
||||
|
||||
if (isNuxt3(nuxt)) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { resolve } from 'pathe'
|
||||
import { importModule } from '../utils/cjs'
|
||||
import { loadKit } from '../utils/kit'
|
||||
import { writeTypes } from '../utils/prepare'
|
||||
import { defineNuxtCommand } from './index'
|
||||
|
||||
@ -13,7 +13,7 @@ export default defineNuxtCommand({
|
||||
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
|
||||
const rootDir = resolve(args._[0] || '.')
|
||||
|
||||
const { loadNuxt } = await importModule('@nuxt/kit', rootDir) as typeof import('@nuxt/kit')
|
||||
const { loadNuxt } = await loadKit(rootDir)
|
||||
const nuxt = await loadNuxt({ rootDir })
|
||||
|
||||
await writeTypes(nuxt)
|
||||
|
12
packages/nuxi/src/utils/kit.ts
Normal file
12
packages/nuxi/src/utils/kit.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { importModule } from './cjs'
|
||||
|
||||
export const loadKit = async (rootDir: string): Promise<typeof import('@nuxt/kit')> => {
|
||||
try {
|
||||
return await importModule('@nuxt/kit', rootDir) as typeof import('@nuxt/kit')
|
||||
} catch (e) {
|
||||
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 e
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user