Skip to content

Windows Path Issue in Generated Import Statements #140

@mrjanjua16

Description

@mrjanjua16

The prisma-field-encryption generator produces incorrect import paths when running on Windows. Instead of using the standard package import @prisma/client, it generates absolute Windows file paths that include backslashes, resulting in TypeScript/JavaScript errors.

Example
When generating migration files on Windows, I get incorrect imports like:

// Incorrect (generated on Windows)
import type { PrismaClient, subscriptions } from '../D:\Personal\Projects\expense-flow\node_modules\@prisma\client'

Instead of the correct format:

// Correct
import type { PrismaClient, subscriptions } from '@prisma/client'

Root Cause
After investigating the source code, I found the issue in main.ts. The generator uses POSIX-style path handling (path/posix) but doesn't properly handle Windows backslashes when determining import paths. The current detection logic only checks for paths ending with 'node_modules/@prisma/client', which misses Windows-style paths.

Reproduction Steps

  1. Create a Next.js/Prisma project on Windows
  2. Set up prisma-field-encryption in schema.prisma
  3. Run npx prisma generate
  4. Observe incorrect import paths in the generated files

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions