Blitz: Fix `@prisma/client` being included in the client side bundle during development

Created on 27 Feb 2020  路  11Comments  路  Source: blitz-js/blitz

The current core and first-demo code runs in production on Zeit now, but it fails during local development:

Failed to compile

/Users/b/c/blitz/node_modules/@prisma/client/runtime/index.js
Module not found: Can't resolve 'child_process' in '/Users/b/c/blitz/node_modules/@prisma/client/runtime'

This issue is up for grabs!

statuready-to-work-on

All 11 comments

is there going to be a next.config.js in the root of core?

This looks like a fix - https://github.com/zeit/next.js/issues/2069#issuecomment-578267894

nevermind - I see what the plan is

I think Blitz will provide a next.config.js wrapper

you already have a next.config.js in the example.

I'll take a shot at this.

I have some work to do to get up to speed though. haven't used TypeScript in a while, and postgres in years....

So if anyone else wants this issue, have at it. :-)

You can switch to sqlite. Change to this in prisma/schema.prisma

datasource db {
  provider = "sqlite" // other options are: "mysql" and "sqlite"
  url = "file:./dev.db"
}

I have a PR for this incoming.

@jimthedev yay, thank you!!

Ok a couple of things. The webpack docs indicate you should be able to just use

if (!isServer) {
      config.resolve.alias['@prisma/client'] = false
}

Unfortunately the version of webpack being used seems to want a string and will not accept false. It seems that perhaps in the future the right approach may be to use false but that won't work for now.

I also looked into the approach using the IgnorePlugin but was getting some strange errors where webpack was putting a ! into the code for the frontend and saying it could not find the modules '@prisma/client` so in that case it seems that it properly ignored the module but that resulted in an error since we aren't providing the module by other means.

So what can we do? As the article @flybayer mentioned we can resolve to a noop file (an empty file) and everything works well. Effectively it operates as a noop until webpack supports the false value. Happy to have others try to confirm but wanted to share what I'd found.

I just posted in the Prisma slack. We'll see what they say.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aaronfulkerson picture aaronfulkerson  路  3Comments

SharadKumar picture SharadKumar  路  3Comments

flybayer picture flybayer  路  4Comments

simonedelmann picture simonedelmann  路  3Comments

timsuchanek picture timsuchanek  路  5Comments