Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package name reuse (.prisma/client) when generating multiple prisma clients causes issues with some other libraries (e.g. jest) #4048

Closed
roderickhodgson opened this issue Oct 27, 2020 · 4 comments · Fixed by #4130
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. tech/typescript Issue for tech TypeScript. topic: generator

Comments

@roderickhodgson
Copy link

roderickhodgson commented Oct 27, 2020

Bug description

prisma generate with custom output settings creates clients all with the same package name ("./prisma/client"). It should use a unique name, such as the output path as the package name.

This causes issues in some dependency management tools, such as jest-haste-map (used by jest@26.6.1), preventing jest from running in projects with more than one client.

This is a typical error you may get as a result of this:

The name `.prisma/client` was looked up in the Haste module map. It cannot be resolved, because there exists several different files, or packages, that provide a module for that particular name and platform. The platform is generic (no extension). You must delete or exclude files until there remains only one of these:

      * `<rootdir>/generated/database/client1/package.json` (package)
      * `<rootdir>/generated/database/client2/package.json` (package)

How to reproduce

  1. Start with a project setup with prisma init, providing enough information for prisma generate to run.
  2. Run prisma generate
  3. Edit generator client in schema file, so that it includes an output directive (output: "../generated/database/client")
  4. Re-run prisma generate
  5. The file at <rootdir>/generated/database/client/package.json is the same as <rootdir>/node_modules/.prisma/client/package.json, and reads as follows:
{
  "name": ".prisma/client",
  "main": "index.js",
  "types": "index.d.ts"
}

Optional: run jest --clearCache to see the impact of this.

Expected behavior

The generated directory to have a package.json as follows (or similar):

{
  "name": "generated/database/client",
  "main": "index.js",
  "types": "index.d.ts"
}

Mitigations

  • Where the client is not required by dependency management tool: Adding the path for generated modules in any relevant exclusion path (e.g. testModuleIgnorePatterns for jest).
  • Otherwise: manually renaming the generated package.json name each time prisma generate is called

Prisma information

generator client {
  provider = "prisma-client-js"
  output   = "../generated/database/client"
}

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

...etc

Environment & setup

I expect this issue arises in all environments. Here is mine:

  • OS: Mac OS
  • Database: MySQL
  • Node.js version: v14.10.1
  • Prisma version: 2.9.0
@pantharshit00
Copy link
Contributor

I can confirm this. We should fix this.

@timsuchanek
Copy link
Contributor

Thanks for reporting @roderickhodgson. The simple solution we came up with and validated with jest, is to remove the package.json from the custom output directories.
It will be merged and shipped on @prisma/client@dev in a bit.

@timsuchanek
Copy link
Contributor

Reopening until we confirmed that the new dev works as intended.

@timsuchanek
Copy link
Contributor

And it is indeed fixed!
You can check it out with @prisma/cli@2.11.0-dev.25 and @prisma/client@2.11.0-dev.25.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. tech/typescript Issue for tech TypeScript. topic: generator
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants