Prisma: Issue properly keeping the prisma2 @prisma/client out of the client side bundle in Next.js

Created on 28 Feb 2020  路  3Comments  路  Source: prisma/prisma

I'm just quoting's @flybayer's message from the Prisma Slack turning it into a public GitHub issue

We鈥檙e currently having an issue properly keeping the prisma2 @prisma/client out of the client side bundle in Next.js, (using it from getServerSideProps).

The Blitz core and example code on the canary branch works properly in production, but not in development.

This blog post shows different ways to do this, but none of them are working when an npm package is requiring @prisma/client.

image

bu0-needs-info kinbug

Most helpful comment

Good news: I found a good solution for this!

  1. yarn install null-loader
  2. Add the following to next.config.js
module.exports = {
  webpack(config, { isServer }) {
    if (!isServer) {
      // Ensure prisma client is not included in the client bundle
      config.module.rules.push({
        test: /@prisma\/client/,
        use: "null-loader",
      })
    }
    return config
  },
}

All 3 comments

Good news: I found a good solution for this!

  1. yarn install null-loader
  2. Add the following to next.config.js
module.exports = {
  webpack(config, { isServer }) {
    if (!isServer) {
      // Ensure prisma client is not included in the client bundle
      config.module.rules.push({
        test: /@prisma\/client/,
        use: "null-loader",
      })
    }
    return config
  },
}

Hey @flybayer,

Now that Next.js 9.3 is out, can you please confirm that you are able to still reproduce this.

If yes, can you share a minimal reproduction in a Git repository? If you can also configure that reproduction with webpack bundle analyzer, that would be super nice.

I'm no longer having this issue! It can be closed

Was this page helpful?
0 / 5 - 0 ratings