【Prisma】npx prisma db seedが実行できない

2023/06/20に公開

はじめに

社内でseedを導入する話になりました
しかし、サンプルコードを記述し、npx prisma db seedを実行しましたが、
下記のエラーでseedが実行出来ませんでした。

$ npx prisma db seed
Environment variables loaded from .env
Running seed command `ts-node prisma/seed/seed.ts` ...
C:\Users\furutan\Work\xxxxxxxxxxxxxxxx\node_modules\typescript\lib\typescript.js:42537
        ts.Debug.assert(typeof typeReferenceDirectiveName === "string", "Non-string value passed to `ts.resolveTypeReferenceDirective`, likely by a wrapping package working with an outdated `resolveTypeReferenceDirectives` signature. This is probably not a problem in TS itself.");
                 ^
Error: Debug Failure. False expression: Non-string value passed to `ts.resolveTypeReferenceDirective`, likely by a wrapping package working with an outdated `resolveTypeReferenceDirectives` signature. This is probably not a problem in TS itself.
    at Object.resolveTypeReferenceDirective 

~~~~~~~~~~~~~~~~~~~~~~~~ 省略 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

An error occurred while running the seed command:
Error: Command failed with exit code 1: ts-node prisma/seed/seed.ts

和訳
.envから環境変数を読み込む
seedコマンド ts-node prisma/seed/seed.ts を実行中 ...
C:¥Usersfurutan¥Work¥xxxxxxxxxxxxxxxx¥node_modules¥typescript¥lib¥typescript.js:42537
ts.Debug.assert(typeof typeReferenceDirectiveName === "string", "ts.resolveTypeReferenceDirective に渡された非文字列の値は、古い resolveTypeReferenceDirectives 署名で動作するラッピングパッケージによる可能性があります。これはおそらくTS自体の問題ではありません」);
^
エラーです: Debug Failure. 偽の式です: これは、古い resolveTypeReferenceDirectives シグネチャで動作するラッピングパッケージによるものと思われます。これは、おそらくTS自体の問題ではありません。
~~~ 省略 ~~~
seedコマンドの実行中にエラーが発生しました:
エラーです: コマンドは終了コード1で失敗しました: ts-node prisma/seed/seed.ts

対象読者

  • 上記のエラーでnpx prisma db seedが実行できない方

この記事でわかること

  • 上記のエラーの解決方法

前提条件

  • ts-node 10.0.0

手順解説

結論

Errorの再現方法

1. ファイル構成の確認

今回は、このようなファイル構成で行いました。

prisma
├── seed
│   ├── userInfoTable
│   │   ├── insertData.ts
│   │   └── insertScript.ts
│   └── seed.ts
└── schema.prisma

2. seedを実行する

npx prisma db seedを実行しましたが、resolveTypeReferenceDirectivesのErrorが発生しました。

$ npx prisma db seed
Environment variables loaded from .env
Running seed command `ts-node prisma/seed/seed.ts` ...
C:\Users\furutan\Work\xxxxxxxxxxxxxxxx\node_modules\typescript\lib\typescript.js:42537
        ts.Debug.assert(typeof typeReferenceDirectiveName === "string", "Non-string value passed to `ts.resolveTypeReferenceDirective`, likely by a wrapping package working with an outdated `resolveTypeReferenceDirectives` signature. This is probably not a problem in TS itself.");
                 ^
Error: Debug Failure. False expression: Non-string value passed to `ts.resolveTypeReferenceDirective`, likely by a wrapping package working with an outdated `resolveTypeReferenceDirectives` signature. This is probably not a problem in TS itself.
    at Object.resolveTypeReferenceDirective 

~~~~~~~~~~~~~~~~~~~~~~~~ 省略 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

An error occurred while running the seed command:
Error: Command failed with exit code 1: ts-node prisma/seed/seed.ts

Errorの解決方法

1. "ts-node"のversionを最新する

調べたら、package.jsonの"ts-node"のversionを最新にしたら解決するみたいなので
npm install ts-node@latestを実行してversionを最新にします。

$ npm install ts-node@latest

up to date, audited 929 packages in 7s

87 packages are looking for funding
  run `npm fund` for details

8 vulnerabilities (3 moderate, 2 high, 3 critical)

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.

2. package.jsonの中身を確認する

package.jsonのts-nodeのversionを確認します。
無事に10.0.0 -> 10.9.1に変更されました。

package.json
-  "ts-node": "^10.0.0",
+  "ts-node": "^10.9.1",

3. seedを再度実行する

$ npx prisma db seed
Environment variables loaded from .env
Running seed command `ts-node prisma/seed/seed.ts` ...
Start seeding ...
Seeding finished.

The seed command has been executed.

先ほどのresolveTypeReferenceDirectivesのErrorは発生せず、ローカルのDBにデータが登録されておりました。

おわりに

seedを初めて触り、よく分からない中
resolveTypeReferenceDirectivesのErrorが発生して苦労しました。
開発のメンバーと一緒に解決できてよかったです。

GitHubで編集を提案

Discussion