Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
6
Help us understand the problem. What is going on with this article?
@sygnas

VSCode + TypeScript の環境構築で "モジュール 〜.vue が見つかりません" とエラーが出る時の対処法

More than 1 year has passed since last update.

TypeScript開発環境を構築してる時にハマったので書いておきます。

エラー

Vueを使った開発中、コンパイルは問題ないのにVSCodeが下記のエラーを表示します。

モジュール 'foo.vue' が見つかりません

よくある対処

プロジェクトルートに下記内容の定義ファイル sfc.d.ts を作れば解決します。

sfc.d.ts
declare module '*.vue' {
  import Vue from 'vue';
  export default Vue;
}

今回の対処

しかしプロジェクトルートはただでさえ設定ファイルが多いので、これ以上増やしたくありません。@typesというフォルダを作り、そこにまとめます。

プロジェクトの一部
.
├── src
│   ├── @types
│   │   └── sfc.d.ts // ここに置いた
│   └── js
│       └── index.ts
└── tsconfig.json

tsconfig.json を編集

tsconfig.json
{
  "compilerOptions": {
 〜略〜
  "include": [
    "./src/js/**/*.ts",
    "./src/js/**/*.tsx",
    "./src/js/**/*.vue",
    "./src/@types/**/*.ts", // これを追加
    "tests/**/*.ts",
    "tests/**/*.tsx",
  ],
 〜略〜
}

tsconfig.json 全文
{
  "compilerOptions": {
    "target": "es5",
    "module": "es2015",
    "strict": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "baseUrl": ".",
    "typeRoots": [
      "./node_modules/@types",
    ],
    "types": [
      "webpack-env",
    ],
    "paths": {
      "@/*": ["./src/js/*"],
    },
    "lib": [
      "es2015",
      "es2015.promise",
      "esnext",
      "dom",
      "dom.iterable",
      "scripthost"
    ]
  },
  "include": [
    "./src/js/**/*.ts",
    "./src/js/**/*.tsx",
    "./src/js/**/*.vue",
    "./src/@types/**/*.ts",
    "tests/**/*.ts",
    "tests/**/*.tsx",
  ],
  "exclude": [
    "node_modules"
  ],
}
```</div>
</details>

6
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
sygnas

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
6
Help us understand the problem. What is going on with this article?