Skip to content

Prisma Client 7 generated code breaks when bundling with Webpack (ESM .js import issue) #28627

Open

Description

@AnthonyGhizzo

Bug description

When using provider = "prisma-client" in Prisma 7 with a custom output path (e.g. ./prisma-generated), Prisma generates TypeScript files such as client.ts that contain imports like:

import { PrismaClientClass } from "./internal/class.js";

However, only class.ts exists, not class.js.

Image

When bundling with Webpack (NestJS), this results in module resolution errors:

Module not found: Error: Can't resolve './internal/class.js'

Why this happens
• Prisma 7 generates ESM-style .js imports in TypeScript files
• These files do not exist yet at build time (class.ts exists, not class.js)
• Webpack does not resolve .js → .ts automatically ?

Image

⸻

This issue causes bundling failures in real-world setups (NestJS monorepos).
It would be helpful if Prisma Client generated TS-friendly import paths or documented this behavior.

-> schema.prisma

generator client {
  provider        = "prisma-client"
  output          = "./prisma-generated"
  previewFeatures = ["fullTextSearchPostgres", "postgresqlExtensions"]
}

datasource db {
  provider   = "postgresql"
  extensions = [postgis]
}

-> prisma.config.ts

import "dotenv/config";
import { defineConfig, env } from "prisma/config";

export default defineConfig({
    schema: "libs/core/src/prisma/schema.prisma",
    migrations: {
        path: "libs/core/src/prisma/migrations",
    },
    datasource: {
        url: env("DATABASE_URL"),
    },
});

Errors

Image

Thanks! 🙏

Environment

Tech Version
Prisma 7.0.0
Node 24.11.1
TS 5.9.x
Runtime Node
PackageMnager Bun
Bundler Webpack (NestJS)
OS macOS ARM64

Activity

  1. linhtrinh18 commented on Nov 21, 2025

    @linhtrinh18

    Facing the same error.

  2. PapaArt commented on Nov 21, 2025

    @PapaArt

    I'm facing the same error I'm stuck in my project cause I cant access the prisma client correctly and then my project can't be compiled, I'm using Windows 11, but I tested on a Mac and got the same issue. I tried to generate the client with the output path and without the path, referencing '@prisma/client' and referencing the generated folder and none of this helped.

  3. fruitsdrink commented on Nov 22, 2025

    @fruitsdrink

    Facing the same error.

  4. aniketicloud commented on Nov 22, 2025

    @aniketicloud

    Facing the same error. I'm using prisma in next js project

  5. piotrberlowski commented on Nov 22, 2025

    @piotrberlowski

    Workaround:

    generator client {
      provider = "prisma-client"
    +  importFileExtension = ""
    }
    

    This changes the "file extension used in import statements" to empty.

  6. jcubic commented on Nov 22, 2025

    @jcubic

    importFileExtension = "" doesn't work for me. I tested every option (proabbly).

  7. piotrberlowski commented on Nov 22, 2025

    @piotrberlowski

    importFileExtension = "" doesn't work for me. I tested every option (proabbly).

    Does the generator ignore this option for you and still generate import statements with file extension then?

  8. jcubic commented on Nov 23, 2025

    @jcubic

    @piotrberlowski this is what I've meant by "not working"

  9. linhtrinh18 commented on Nov 24, 2025

    @linhtrinh18

    Avoid using the "@prisma/client" in any type of server components, as it will fail when it comes to build/compile the project.

  10. jkomyno commented on Nov 24, 2025

    @jkomyno
    Contributor

    Hi @AnthonyGhizzo and others, please always provide a minimal reproduction, otherwise we won't be able to investigate the problem you're facing.

    In the meantime:

    Thanks!

  11. jcubic commented on Nov 24, 2025

    @jcubic

    @jkomyno Will try to create a minimal example with Next.js that I use. In the meantime, I can share my project if you want.

  12. AnthonyGhizzo commented on Nov 24, 2025

    @AnthonyGhizzo
    Author

    Hi @AnthonyGhizzo and others, please always provide a minimal reproduction, otherwise we won't be able to investigate the problem you're facing.

    In the meantime:

    Thanks!

    Thank you for your response, I have just updated the issue.

  13. jcubic commented on Nov 24, 2025

    @jcubic

    @AnthonyGhizzo Minimal reproduction is code that you can run, that isolate the issue and have minimal amount of code. See Wikipedia: Minimal reproducible example

  14. AnthonyGhizzo commented on Nov 25, 2025

    @AnthonyGhizzo
    Author

    A temporary solution I found is:

    1- Remove "type": "module" from the package.json (even though the Prisma 7 documentation recommends keeping it).
    2- Create a webpack.config.cjs file with:

    module.exports = (options, webpack) => {
        return {
            ...options,
            resolve: {
                ...options.resolve,
                extensionAlias: {
                    ".js": [".ts", ".tsx", ".js", ".jsx"],
                },
            },
        };
    };
    

    3- (In my case, I’m using a NestJS environment)
    Update the nest-cli.json file with:

    "compilerOptions": {
        "deleteOutDir": true,
        "webpack": true,
        "webpackConfigPath": "webpack.config.cjs"
    }
    

    After applying these changes, the project compiles successfully.

  15. jcubic commented on Nov 25, 2025

    @jcubic

    The workaround doesn't work in Next.js. I've tried to customize Webpack via Next config:

    const nextConfig: NextConfig = {
      ...
      turbopack: {},
      webpack: (config, { isServer }) => {
        config.module.resolve ??= {};
        config.module.resolve.extensionAlias = {
          '.js': ['.ts', '.tsx', '.js', '.jsx'],
        };
        return config;
      }
    };

    and got same error

  16. sohaibkhalid-dev commented on Nov 28, 2025

    @sohaibkhalid-dev

    A temporary solution I found is:

    1- Remove "type": "module" from the package.json (even though the Prisma 7 documentation recommends keeping it). 2- Create a webpack.config.cjs file with:

    module.exports = (options, webpack) => {
        return {
            ...options,
            resolve: {
                ...options.resolve,
                extensionAlias: {
                    ".js": [".ts", ".tsx", ".js", ".jsx"],
                },
            },
        };
    };
    

    3- (In my case, I’m using a NestJS environment) Update the nest-cli.json file with:

    "compilerOptions": {
        "deleteOutDir": true,
        "webpack": true,
        "webpackConfigPath": "webpack.config.cjs"
    }
    

    After applying these changes, the project compiles successfully.

    You don't need to do this. try the official way
    https://docs.nestjs.com/recipes/prisma
    generator client {
    provider = "prisma-client"
    output = "../src/generated/prisma"
    moduleFormat = "cjs"
    }

    You just need to add moduleFormat.

  17. wppaing commented on Nov 29, 2025

    @wppaing

    bump

  18. jcubic commented on Nov 29, 2025

    @jcubic

    This solves the problem on my end:

    generator client {
      provider             = "prisma-client"
      output               = "../prisma-main/types"
      binaryTargets        = ["native", "linux-musl", "rhel-openssl-3.0.x"]
      moduleFormat = "esm"
      generatedFileExtension = "ts"
      importFileExtension = "ts"
    }
    

    Found in this issue:

  19. added
    bug/1-unconfirmed
    on Dec 11, 2025
  20. devanshtakkar commented on Dec 13, 2025

    @devanshtakkar

    This solves the problem on my end:

    generator client {
      provider             = "prisma-client"
      output               = "../prisma-main/types"
      binaryTargets        = ["native", "linux-musl", "rhel-openssl-3.0.x"]
      moduleFormat = "esm"
      generatedFileExtension = "ts"
      importFileExtension = "ts"
    }
    

    Found in this issue:

    This actually solved the issue. Thank you

  21. BonaparteIT commented on Jan 1, 2026

    @BonaparteIT

    Workaround:

    generator client {
      provider = "prisma-client"
    +  importFileExtension = ""
    }
    

    This changes the "file extension used in import statements" to empty.

    this works for my stack NestJS + Prisma 7.2.0

  22. ahmed8mansour commented on Jan 6, 2026

    @ahmed8mansour

    This solves the problem on my end:

    generator client {
      provider             = "prisma-client"
      output               = "../prisma-main/types"
      binaryTargets        = ["native", "linux-musl", "rhel-openssl-3.0.x"]
      moduleFormat = "esm"
      generatedFileExtension = "ts"
      importFileExtension = "ts"
    }
    

    Found in this issue:

    finally , this solves the issue , thanks

  23. mdtausifiqbal commented on Jan 17, 2026

    @mdtausifiqbal

    @AnthonyGhizzo To solve this error, I changed generator setting and run prisma generate command this fixed my error

    generator client {
      provider = "prisma-client"
      output   = "../src/generated/prisma"
    
      generatedFileExtension = "ts"
      importFileExtension    = ""
    }
    
    Image
  24. Djurdjijan commented on Jan 26, 2026

    @Djurdjijan

    The only working solution in Nest.js is this:

    add this to your webpack.config.js with

    module.exports = function (options) {
      return {
        ...options,
        resolve: {
          ...options.resolve,
          extensionAlias: {
            '.js': ['.ts', '.js'],
            '.mjs': ['.mts', '.mjs'],
          },
        },
      };
    };
    

    Update nest.cli.json as well:

    {
      "compilerOptions": {
        "webpackConfigPath": "webpack.config.js"
      }
    }
    

    schema.prisma example

    generator client {
      provider = "prisma-client"
      output   = "../libs/shared/src/database/prisma/client"
    }
    
    datasource db {
      provider = "mysql"
    }
    

    PrismaService.ts Example

    import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
    import { PrismaClient } from '../../../../shared/src/database/prisma/client/client';
    import { PrismaMariaDb } from '@prisma/adapter-mariadb';
    
    @Injectable()
    export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
      constructor() {
        const adapter = new PrismaMariaDb({
          host: process.env.DB_HOST || 'localhost',
          port: parseInt(process.env.DB_PORT || '3306', 10),
          user: process.env.DB_USER || 'prisma',
          password: process.env.DB_PASSWORD || 'prisma123',
          database: process.env.DB_NAME || 'prismadb',
          connectionLimit: 10,
        });
        
        super({ adapter });
      }
    
      async onModuleInit() {
        await this.$connect();
      }
    
      async onModuleDestroy() {
        await this.$disconnect();
      }
    }
    
  25. QuDaMyker commented on Mar 21, 2026

    @QuDaMyker

    provider = "prisma-client"
    output = "../prisma-main/types"
    binaryTargets = ["native", "linux-musl", "rhel-openssl-3.0.x"]
    moduleFormat = "esm"
    generatedFileExtension = "ts"
    importFileExtension = "ts"

    Love you so much, f*cking example Prisma Nestjs not working

  26. JonKazama-Hellion commented on Mar 27, 2026

    @JonKazama-Hellion

    Adding my experience with this issue on a self-hosted Windows Server setup.

    Environment:

    • Next.js 16.2.1 with webpack (not Turbopack)
    • Prisma 7.5.0 with @prisma/adapter-mariadb (MySQL 9.5.0)
    • Windows Server 2025, IIS Reverse Proxy, deployed via Task Scheduler
    • Node.js 22.x, ESM ("type": "module")

    What happened:
    After a full migration from Prisma 6 to 7 (including prisma-client generator, prisma.config.ts, driver adapter, all import paths updated), the build succeeded locally on Linux without any errors (typecheck, lint, build all clean).

    On the Windows Server, the site started throwing intermittent 502 Bad Gateway errors — but neither Next.js nor IIS logged any error messages. The failure was completely silent. Some pages worked fine (static/cached), while pages requiring database access would fail.

    The root cause is the generated client.ts:

    globalThis['__dirname'] = path.dirname(fileURLToPath(import.meta.url))

    import.meta.url is undefined in webpack server bundles, causing:

    TypeError: The URL must be of scheme file
    

    Why this was hard to diagnose:
    The crash happens during module loading, before Next.js can handle or log the error. IIS only sees "backend not responding" and returns 502. It took a full server restart to force the bundler to re-initialize all modules, which finally surfaced the actual database connection errors that pointed to Prisma.

    Workaround attempted:
    I wrote a post-generate patch script replacing the hard fileURLToPath(import.meta.url) call with a fallback chain (import.meta.url → __dirname → process.cwd()). This worked on Linux but still caused issues on the Windows Server environment.

    Resolution:
    Reverted to Prisma 6.19.2. Everything works again immediately.

    This is a blocker for self-hosted webpack deployments. The silent failure mode makes it especially dangerous — there's no indication that Prisma is the cause until you happen to trigger a full re-initialization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/1-unconfirmedkind/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions