Skip to content

ESM (.mjs) modules of TypedSQL client use CommonJS imports when generating to a non-default location #25259

@solarisn

Description

@solarisn

Bug description

When generating the prisma client with --sql flag to a non-default location, the generated .mjs files use CommonJS import syntax which is invalid ESM code.

How to reproduce

  1. Setup prisma client w/ at least 1 SQL query in the "sql" folder and output the generated client to a non-default location. In this example, the 1 sql query file will be ./prisma/sql/getFeed.sql
generator client {
  ...
  output          = "client"
  previewFeatures = ["typedSql"]
}
  1. Generate the client with sql flag npx prisma generate --sql
  2. Inspect the generated ESM module for the SQL query at ./prisma/client/sql/getFeed.mjs. Note that the import statement at the top uses CJS import syntax and is missing the .js extension from the runtime library module.
import { makeTypedQueryFactory as $mkFactory } from "../runtime/library"
export const getFeed = /*#__PURE__*/ $mkFactory("<EXAMPLE>")

Expected behavior

The ESM version of the generated client uses a CJS import making it invalid code. Currently this is generated at ./prisma/client/sql/getFeed.sql:

import { makeTypedQueryFactory as $mkFactory } from "../runtime/library"

Instead, I expect this to be generated with ".js" extension:

import { makeTypedQueryFactory as $mkFactory } from "../runtime/library.js"

Prisma information

generator client {
  ...
  output          = "client"
  previewFeatures = ["typedSql"]
}

Environment & setup

  • OS: macOS
  • Database: PostgreSQL
  • Node.js version: 18

Prisma Version

5.19.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/1-unconfirmedBug should have enough information for reproduction, but confirmation has not happened yet.kind/bugA reported bug.topic: esmtopic: typedSql

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions