prisma: Generating client to custom location with Next.js is broken

Bug description

Iโ€™m using a custom schema location and custom prisma client location. And itโ€™s failing.

  • Schema: db/schema.prisma
  • Client: db/.generated-prisma-client
(node:1879) UnhandledPromiseRejectionWarning: Error: Query engine binary for current platform "darwin" could not be found.
This probably happens, because you built Prisma Client on a different platform.
(Prisma Client looked in "/query-engine-darwin")
Files in /:
  .DS_Store
  .VolumeIcon.icns
  .file
  .fseventsd
  .vol
  Applications
  Library
  Preboot
  System
  Users
  Volumes
  bin
  cores
  dev
  etc
  home
  opt
  private
  sbin
  tmp
  usr
  var
You already added the platform "native" to the "generator" block
in the "schema.prisma" file as described in https://pris.ly/d/client-generator,
but something went wrong. That's suboptimal.
Please create an issue at https://github.com/prisma/prisma-client-js/issues/new

How to reproduce

  1. Check out https://github.com/blitz-js/blitz/pull/124: git clone -b prisma-gen git@github.com:blitz-js/blitz.git
  2. yarn
  3. yarn build
  4. cd examples/store
  5. Set your DATABASE_URL environment variable for postgres
  6. yarn blitz db migrate
  7. yarn blitz start
  8. Open http://localhost:3000/admin/products
  9. See error in console.

Expected behavior

Should work

Environment & setup

  • OS: macOS
  • Database: PostgreSQL
  • Prisma version: 2.0.0-alpha.1081"
  • Node.js version: 12.6.1

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 21 (12 by maintainers)

Commits related to this issue

Most upvoted comments

Just tried it out - I can confirm that this is fixed in the latest version. Let me know if you face any further issues @colinhacks and @flybayer ๐Ÿ™‚

Perhaps that config could be added to https://github.com/prisma-labs/next-prisma-plugin?

EDIT: This breaks dev mode ๐Ÿ˜• https://github.com/prisma/prisma/issues/2195#issuecomment-717576013

I solved this issue for myself by doing a couple things:

  1. overriding the node.__dirname Webpack setting inside next.config.js so itโ€™s true in development and false in production.
  2. Copying the binary into the appropriate folders of .next/serverless using copy-webpack-plugin
// node.config.js

const CopyWebpackPlugin = require('copy-webpack-plugin'); // npm install copy-webpack-plugin
const path = require('path');

module.exports = {
  // stuff here
  webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
    
    // set to `dev`
    config.node.__dirname = dev;
    
    // copy binary into the appropriate locations within `.next/serverless`
    config.plugins.push(
      new CopyWebpackPlugin({
        patterns: [
          {

            // the custom location the binary is generated to
            from: path.join(
              __dirname,
              'path/to/binary/query-engine*', // glob pattern that matches all query-engines
            ),

            to: path.join(__dirname, '.next/serverless/pages/api'),
          },
        ],
      }),
    );

    
    return config;
  },
};

This solution was first proposed here.

Related issues: