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?

Nx 利用時、FrourioNext の OpenAPI 生成でエラーが出る場合の回避方法

Last updated at Posted at 2025-04-30

FrourioNext を Nx 環境で導入してみたところ、OpenAPI 生成がうまく動作しなかった。この記事では、初期構築の手順から、発生したエラー内容、そして最終的に力技での回避方法までをまとめます。


✅ 初期構築

npx create-nx-workspace@latest --pm pnpm
✔ Where would you like to create your workspace? · org
✔ Which stack do you want to use? · none
✔ Would you like to use Prettier for code formatting? · No
✔ Which CI provider would you like to use? · skip
✔ Would you like remote caching to make your build faster? · skip

cd org
npx nx add @nx/next
npx nx g @nx/next:app apps/frourio-app
✔ Which stylesheet format would you like to use? · css
✔ Which linter would you like to use? · none
✔ What unit test runner should be used? · none
✔ Which E2E test runner would you like to use? · none
✔ Would you like to use the App Router (recommended)? · Yes
✔ Would you like to use the `src/` directory? · Yes

必要な依存関係を追加:

pnpm add next zod
pnpm add @frourio/next npm-run-all --save-dev

package.json にスクリプトを追加:

{
  "scripts": {
    "dev": "run-p dev:*",
    "dev:next": "nx dev frourio-app",
    "dev:frourio": "cd apps/frourio-app && frourio-next --watch",
    "build:openapi": "cd apps/frourio-app && frourio-next-openapi --output=./public/openapi.json"
  }
}

💥 エラー発生

pnpm build:openapi を実行すると、以下のエラーが発生:

File '.../frourio.ts' is not listed within the file list of project ''. Projects must list all files or use an 'include' pattern.
Cannot find global type 'Array'.
Option 'customConditions' can only be used when 'moduleResolution' is set to 'node16', 'nodenext', or 'bundler'.
Composite projects may not disable incremental compilation.

試したこと

  • ts-node / @types/node を追加
    → グローバル型のエラーは消えたが、残りの問題は解決せず
pnpm add -D ts-node @types/node
  • moduleResolution: bundler に変更
    customConditions エラーとトレードオフ発生
  • customConditions: ["development"] を削除
    → 一部解決

しかし、frourio.tsproject に含まれていない旨のエラーがしつこく残る。


🛠 最終的な解決方法(力技)

どうにもならず、Nx環境でなければ動作したので、Next環境初期構築時に作成されるのtsconfig.jsonを借りて解決しました。

npx create-next-app@latest next-app

作成された tsconfig.jsonapps/frourio-app/tsconfig.json に一時的に上書きすると、pnpm build:openapi が成功:

{
  "compilerOptions": {
    "target": "ES2017",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "bundler",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [{ "name": "next" }],
    "paths": {
      "@/*": ["./src/*"]
    }
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
  "exclude": ["node_modules"]
}

💡 pnpm build:openapi の前に tsconfig.json を差し替え、実行後に元に戻すスクリプトを書いてもよい。


📝 まとめ

  • Nx + FrourioNext の組み合わせでは tsconfig 周りの互換性に注意
  • ts-node, @types/node の導入は必須
  • moduleResolutioncustomConditions の相性に注意
  • File is not listed within the file list of project のエラーは tsconfig の include や構成そのものが原因?
  • Next.js の tsconfig を一時的に使えば回避可能

この構成が安定して使えるかどうかは今後次第ですが、同じように詰まった方の参考になれば幸いです。

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?