question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"TypeError: Cannot read property 'datasources' of undefined" after command "prisma db reset"

See original GitHub issue

Using prisma client 2.13.1 the issue https://github.com/prisma/migrate/issues/653 remains.

The issue was (see link for more details) :

$ yarn blitz db reset 
yarn run v1.22.5
$ /PATH_TO_MY_APP/node_modules/.bin/blitz db reset
You are using alpha software - if you have any problems, please open an issue here:
    https://github.com/blitz-js/blitz/issues/new/choose

✔ Loading your database
✔ Are you sure you want to reset your database and erase ALL data? (y/N) · true
  tryLoadEnv Environment variables loaded from /PATH_TO_MY_APP/.env +0ms
  tryLoadEnv Environment variables loaded from /PATH_TO_MY_APP/.env +2ms
  prisma-client { clientVersion: '2.13.1' } +0ms
    TypeError: Cannot read property 'datasources' of undefined
Done in 4.54s.

My new env:

$ ./node_modules/.bin/prisma -v
Environment variables loaded from .env
@prisma/cli          : 2.13.1
@prisma/client       : 2.13.1
Current platform     : debian-openssl-1.1.x
Query Engine         : query-engine fcbc4bb2d306c86c28014f596b1e8c7980af8bd4 (at node_modules/@prisma/engines/query-engine-debian-openssl-1.1.x)
Migration Engine     : migration-engine-cli fcbc4bb2d306c86c28014f596b1e8c7980af8bd4 (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine : introspection-core fcbc4bb2d306c86c28014f596b1e8c7980af8bd4 (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary        : prisma-fmt fcbc4bb2d306c86c28014f596b1e8c7980af8bd4 (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Studio               : 0.329.0
Done in 1.94s.

$ node -v
v14.15.3

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Jolg42commented, Jan 7, 2021

It looks like the problem is from Blitz’s implementation here https://github.com/blitz-js/blitz/blob/canary/packages/cli/src/commands/db.ts#L261-L301

It’s using some parts of Prisma that are undocumented / reserved for internal use and something is probably not working as expected.

I think this issue needs to be opened in Blitz’s repo https://github.com/blitz-js/blitz/issues/new/choose

1reaction
etiennekintzlercommented, Jan 7, 2021

Hey @Jolg42

It sounds like the datasource block is missing in the schema, it would be useful if you could share the contents of the schema.prisma file here

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider = "prisma-client-js"
}

the variable "DATABASE_URL" is well defined in .env.

  • I try datasources instead of datasource but the result is the same.

I also try to remove the whole datasource block and the result is the same, which make me think that the problem might be that the command reset doesn’t really consider the schema.prisma file.

There is also no issues with the command migrate. Also when I remove the block datasource of the schema.prisma and run migrate it fails appropriately.

$ PATH_TO_MYAPP/node_modules/.bin/blitz db migrate
You are using alpha software - if you have any problems, please open an issue here:
    https://github.com/blitz-js/blitz/issues/new/choose

  prisma Environment variables not loaded (--schema was provided) +0ms
Error: Error: P1012

Get config 
error: Error validating: You defined no datasource. You must define exactly one datasource.
  -->  schema.prisma:1
   | 
   | 
 1 | // This is your Prisma schema file,
   | 

Validation Error Count: 1

    at Object.<anonymous> (PATH_TO_MYAPP/node_modules/@prisma/cli/build/index.js:2:1654987)
    at Generator.throw (<anonymous>)
    at rejected (PATH_TO_MYAPP/node_modules/@prisma/cli/build/index.js:2:1650422)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
Done in 1.93s.

It’s not clear why the command reset doesn’t fail in the same way when removing the datasource block.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"TypeError: Cannot read property 'datasources' of undefined ...
Bug description prisma db reset fails with error message: TypeError: Cannot read property 'datasources' of undefined The output with env ...
Read more >
Error message reference - Prisma
Prisma Client throws a PrismaClientUnknownRequestError exception if the query engine returns an error related to a request that does not have an error...
Read more >
"Property does not exist" when I want to use model added in ...
I tried prisma generate and prisma migrate dev but was still having the same error. I had to restart VSCode and everything is...
Read more >
Prisma | NestJS - A progressive Node.js framework
You are going to build a sample NestJS application with a REST API that can read and write data in a database. For...
Read more >
Database problems - Get Help and Help Others
That error most often occurs when the DB either doesn't exist (local development) or it's not connected/updated. For local development, after ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found