-
Notifications
You must be signed in to change notification settings - Fork 2.1k
ESM (.mjs) modules of TypedSQL client use CommonJS imports when generating to a non-default location #25259
Copy link
Copy link
Open
Labels
bug/1-unconfirmedBug should have enough information for reproduction, but confirmation has not happened yet.Bug should have enough information for reproduction, but confirmation has not happened yet.kind/bugA reported bug.A reported bug.topic: esmtopic: typedSql
Description
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
- 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"]
}
- Generate the client with sql flag
npx prisma generate --sql - 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.jsextension 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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bug/1-unconfirmedBug should have enough information for reproduction, but confirmation has not happened yet.Bug should have enough information for reproduction, but confirmation has not happened yet.kind/bugA reported bug.A reported bug.topic: esmtopic: typedSql