找不到名称“defineNuxtConfig”.ts(2304)

wyp*_*ama 12 nuxt.js nuxt3

我尝试使用turborepo 在 monorepo 中安装 Nuxt 3 层。我不知何故在打字稿中遇到错误,它似乎无法弄清楚 nuxt

找不到defineNuxtConfig

找不到应用程序配置

ts 配置文件如下所示:

{
  "extends": "./.playground/.nuxt/tsconfig.json"
}

Run Code Online (Sandbox Code Playgroud)

在 .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"
  ]
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题以便正确识别defineNuxtConfig?

删除错误找不到名称“defineNuxtConfig”.ts(2304)

小智 30

我也遇到了同样的问题,奇怪的是,在尝试了一些解决方法后,我将 VSCode 插件 Volar:Typescript Version 更改为Use workspace versionTHEN 更改回Use VS Code's Version

图像

如何:

  1. 在 VSCode 上按F1Ctrl + Shift + P
  2. 类型Volar: Select Typescript Version
  3. 选择Use workspace version
  4. 重复步骤 1 和 2
  5. 但这次选择Use VS Code's Version

Bam,我所有的 nuxt3 自动导入都正确输入,但不知道为什么。


Rez*_*our 8

不是自动解决方案,但您可以手动导入符号:

import { defineNuxtConfig } from 'nuxt/config'
Run Code Online (Sandbox Code Playgroud)