LoginSignup
3
1

More than 3 years have passed since last update.

nuxt-ts を使っていて、"No pages directory found in 〜"と表示されたときの対処

Posted at

NuxtでTypeScriptを使ってデフォルトのsrcディレクトリを変更していると、たまに No pages directory found in プロジェクトディレクトリ と表示されてビルドできないことがあります。

自分はかなりハマってしまったので、対処法をまとめます。

srcDir は設定しているか

srcディレクトリを /appにする場合、
nuxt.configに srcDir: 'app/', と記述します。
https://nuxtjs.org/api/configuration-srcdir#the-srcdir-property

これは基本なので、ちゃんと設定してあるはずですので、おそらく原因は別のところでしょう。

tsconfig.json の設定

baseUrl や paths は正しく設定されているか。

tsconfig.json
{
  "compilerOptions": {
    "baseUrl": "app",
    "paths": {
      "~/*": ["./*"],
      "@/*": ["./*"]
    }
  }
}

モジュールを正しく読み込んでくれないときなどは、
tsconfig-paths は入れてみる

yarn add -D tsconfig-paths

package.json パッケージのバージョン 依存関係は問題ないか

これが一番やっかいな問題ですが、パッケージの依存関係に問題がないか確認します。
node_modules/yarn.lock は削除してクリーンな状態でパッケージを再インストールします。

以前あったのは、パッケージをアップグレードしたときに、core-jsのv3系がnuxtで動かなくなることがありました。

今回の自分が遭遇した原因は、Nuxt TypeScript に書いてあったのですが、nuxtのバージョンと、@nuxt/typescript-runtimeのバージョンの依存問題だったようです。

@nuxt/types
@nuxt/typescript-build
@nuxt/typescript-runtime
These packages are intended to only be used with Nuxt 2.10 or above.

3
1
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
3
1