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

问题描述 投票:0回答:3

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

defineNuxtConfig not find

appConfig not found

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)

nuxt.js nuxt3
3个回答
14
投票

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

Use workspace version
然后改回
Use VS Code's Version

image

如何:

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

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


6
投票

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

import { defineNuxtConfig } from 'nuxt/config'

0
投票

删除 node_modules 文件夹并进行全新安装

npm ci

© www.soinside.com 2019 - 2024. All rights reserved.