はじめに
ドキュメントに従って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をコピペしたり、ドキュメントに沿ってやったりしていて中身を考えることはほとんどありませんでした。
今回調べてみて意味を少し理解することができました。