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?

prisma init --output 実行時の「is not under 'rootDir'」「'rootDir' is expected to contain all source files. 」エラーの解決方法

0
Posted at

はじめに

ドキュメントに従ってPrismaのセットアップをしている際に、エラーが発生しました。

問題

実行したコマンド

npx prisma init --output ../generated/prisma

発生したエラー

File '/Users/user/workspace/projects/my-app/backend/prisma.config.ts'
is not under 'rootDir' '/Users/user/workspace/projects/my-app/backend/src'.
'rootDir' is expected to contain all source files. 
The file is in the program because: Matched by default include pattern '**/*'

解決方法

tsconfig.jsonのexcludeにファイルを追加する

{
  "compilerOptions": {
    "verbatimModuleSyntax": true,
    "skipLibCheck": true,
    "types": ["node"],
    "jsx": "react-jsx",
    "jsxImportSource": "hono/jsx",
    "rootDir": "./src",
    "outDir": "./dist",
    "module": "ESNext",
    "moduleResolution": "bundler",
    "target": "ES2023",
    "strict": true,
    "esModuleInterop": true,
    "ignoreDeprecations": "6.0"
  },
- "exclude": ["node_modules"]
+ "exclude": ["node_modules", "prisma.config.ts"]
}

コンパイル対象のファイルはsrc配下にあるとrootDirで定義されているにもかかわらず、prismaがその外にtsファイルを生成してしまったことが原因のようです。
なので、今回はそのファイルをコンパイル対象から除外しました。

おわりに

設定ファイルはいつもQiitaをコピペしたり、ドキュメントに沿ってやったりしていて中身を考えることはほとんどありませんでした。
今回調べてみて意味を少し理解することができました。

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?