0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[備忘録]Nuxt3でtsconfig.jsonにincludesを追加する場合の注意点

Posted at

モノリポでサーバー側を別プロジェクト化していて、ファイルを共有する場合にtsconfig.jsonの修正でちょっとはまったので備忘録を残しておきます。

project
 packages
  └ front
    └ tsconfig.json
  └ server
    └ src
      └ shared // フロント/サーバー共用ファイル置き場

※前提として、nuxt.config.tsでrootDir: 'src',を指定しています

はまったこと

tsconfig.jsonに"include": ["./**/*", "../server/src/shared/**/*"]を追加したところ、VSCodeで名前解決が出来なくなった

project/packages/front/tsconfig.json
{
  // https://v3.nuxtjs.org/concepts/typescript
  "extends": "./src/.nuxt/tsconfig.json",
  "vueCompilerOptions": {
    "experimentalDisableTemplateSupport": true
  },
  "compilerOptions": {
    "jsx": "preserve",
    "typeRoots": ["./src/types"]
  },
  "include": ["./**/*", "../server/src/shared/**/*"]
}

原因

extendsしている.nuxt/tsconfig.jsonでincludeが定義されて入れ、上書きしてしまって型定義ファイルnuxt.d.tsのincludeが出来なくなっている

project/packages/front/src/.nuxt/tsconfig.json
// Generated by nuxi
{
  "compilerOptions": {
    ・・・
  },
  "include": [
    "./nuxt.d.ts",
    "../**/*"
  ]
}

解決

tsconfig.jsonに"files": ["./src/.nuxt/nuxt.d.ts"]を追加し、Nuxtの型定義ファイルを直接読み込むようにする

project/packages/front/tsconfig.json
{
  // https://v3.nuxtjs.org/concepts/typescript
  "extends": "./src/.nuxt/tsconfig.json",
  "vueCompilerOptions": {
    "experimentalDisableTemplateSupport": true
  },
  "compilerOptions": {
    "jsx": "preserve",
    "typeRoots": ["./src/types"]
  },
  "files": ["./src/.nuxt/nuxt.d.ts"],
  "include": ["./**/*", "../server/src/shared/**/*"]
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?