我尝试使用 Turborepo 在 monorepo 中安装 Nuxt 3 层。我不知何故在打字稿中遇到错误,它似乎无法弄清楚 nuxt
ts 配置文件如下所示:
{
"extends": "./.playground/.nuxt/tsconfig.json"
}
在 .playground/.nuxt 文件夹中,有 tsconfig 看起来像这样(自动生成):
// Generated by nuxi
{
"compilerOptions": {
"forceConsistentCasingInFileNames": true,
"jsx": "preserve",
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Node",
"skipLibCheck": true,
"strict": true,
"allowJs": true,
"noEmit": true,
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"types": [
"node"
],
"baseUrl": "..",
"paths": {
"~": [
"."
],
"~/*": [
"./*"
],
"@": [
"."
],
"@/*": [
"./*"
],
"~~": [
"."
],
"~~/*": [
"./*"
],
"@@": [
"."
],
"@@/*": [
"./*"
],
"assets": [
"assets"
],
"public": [
"public"
],
"#app": [
"../../../node_modules/nuxt/dist/app"
],
"#app/*": [
"../../../node_modules/nuxt/dist/app/*"
],
"vue-demi": [
"../../../node_modules/nuxt/dist/app/compat/vue-demi"
],
"@vueuse/head": [
"../../../node_modules/@unhead/vue/dist/index"
],
"#imports": [
".nuxt/imports"
],
"#build": [
".nuxt"
],
"#build/*": [
".nuxt/*"
],
"#components": [
".nuxt/components"
]
}
},
"include": [
"./nuxt.d.ts",
"../**/*"
],
"exclude": [
"../dist",
"../.output"
]
}
我该如何解决这个问题以便正确识别defineNuxtConfig?
删除错误 Cannot find name 'defineNuxtConfig'.ts(2304)
我也遇到了同样的问题,奇怪的是,在尝试了一些解决方法后,我将 VSCode 插件 Volar:Typescript Version 更改为
Use workspace version
然后改回 Use VS Code's Version
如何:
F1
或 Ctrl + Shift + P
Volar: Select Typescript Version
Use workspace version
Use VS Code's Version
Bam,我所有的 nuxt3 自动导入都正确输入,但不知道为什么。
不是自动解决方案,但您可以手动导入符号:
import { defineNuxtConfig } from 'nuxt/config'
删除 node_modules 文件夹并进行全新安装
npm ci