prisma: I get "Can't resolve '_http_common'" when I use NestJS with monorepo (webpack)

Bug description

When I try to composite Prisma with NestJS monorepo project I get the error. I can`t use default prisma client output path because my projects use prisma client and each project overrides before generated client files. I try to use custom output path but I get the error. I found some information about the error -> https://github.com/restify/node-restify/issues/794.

How to reproduce

Steps to reproduce the behavior:

  1. Create new app as monorepo project
  2. Generate client in custom output path. For example “output = …/src/prisma/client”
  3. Execute command “build”
  4. See error “Can’t resolve ‘_http_common’”

Expected behavior

Build happy project

Environment & setup

  • OS: Mac OS
  • Database: PostgreSQL
  • Node.js version: 12.22.1
  • Prisma version: 2.21.2
datasource db {
  provider	=	"postgresql"
  url	=	env("MAIN_DATABASE_URL")
}

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

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 31 (9 by maintainers)

Commits related to this issue

Most upvoted comments

For me is working to get client generated as below:

generator client {
  provider        = "prisma-client-js"
  output          = "../../../node_modules/@~internal/prisma"
}

Then you can import it from anywhere like:

import {PrismaClient} from '@~internal/prisma'

Hope it helps.

Also sad to report that I didn’t find a workaround other than not upgrading prisma or webpack 😢

But it does look like v4 of unidici is in release candidate stages

Hey everyone, this has been fixed in @prisma/client@dev if you want to give it a try. Please let us know if you find anything unexpected. Thanks.

(cc @VincentThomas06 @j0hnm4r5 @juanzgc)

I excluded _http_common from webpack. The build completed but when I start my project I get an error “_http_common is not defined”. I created new branch master-webpack for reproduce this case.

webpack.config.js

module.exports = function(options) {
  return {
    ...options,
    target: 'node',
    externals: [...options.externals, '_http_common']
  };
};

You’re right, I had to update @prisma/client to 3.15.2 (and not just prisma as I had done previously), and it is working now 👍

Hey @Frankitch @VincentThomas06 👋 I think I understood the issue. When you generate to the default location, the client gets generated with a package.json in which there is a browser field. This field is used by webpack to bundle for the web (default). But because it’s generated outside of node_modules, we don’t create such package.json. Maybe for good reasons? Maybe not?

The next steps will simple. I’ll need to setup a repro, you’re very welcome to help me there if you already have one. And that is just to make sure we are fixing the right problem. Then, I will let us output a package.json in custom locations to and see if webpack/nestjs can pick that up automatically. If that fails, I will provide you with a workaround.

Thus, I’m closing this issue about _http_common, but don’t worry we will be tracking the work to come via #12607

Thanks!

Hey @ahmadalfy, sorry about this. We have a fix ready but that is unfortunately blocked due to memory leak issues. That will need to be prioritized first (and investigated) before we can merge the fix.

@millsp here’s a reproduction repo that clearly shows what’s going on (with instructions): https://github.com/j0hnm4r5/example-prisma-next-auth-monorepo

I really appreciate all your help!