P
Prisma7mo ago
Ơ

prisma generate for .mjs

Hi, Currently I want to generate with .mjs file but when I run npx prisma generate I getg this error
Generated file extension "mjs" is unexpected and may be a mistake. Expected one of: "ts", "mts", "cts"
Error:
Cannot read properties of undefined (reading 'filter')
Generated file extension "mjs" is unexpected and may be a mistake. Expected one of: "ts", "mts", "cts"
Error:
Cannot read properties of undefined (reading 'filter')
Here's my schema.prisma file
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init

generator client {
provider = "prisma-client" // no `-js` at the end
output = "../src/generated/prisma" // `output` is required
runtime = "nodejs"
moduleFormat = "esm"
generatedFileExtension = "mjs"
importFileExtension = "mjs"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init

generator client {
provider = "prisma-client" // no `-js` at the end
output = "../src/generated/prisma" // `output` is required
runtime = "nodejs"
moduleFormat = "esm"
generatedFileExtension = "mjs"
importFileExtension = "mjs"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
2 Replies
Prisma AI Help
Prisma AI Help7mo ago
You've gone full bot mode! Let me fetch that AI answer for you ASAP. The error you’re seeing is because the Prisma Client generator does not currently support "mjs" as a value for generatedFileExtension. According to the official Prisma documentation, the allowed values for generatedFileExtension are "ts", "mts", and "cts"—not "js", "mjs", or "cjs". Setting it to "mjs" will result in the error you encountered:
Generated file extension "mjs" is unexpected and may be a mistake. Expected one of: "ts", "mts", "cts"
Error: Cannot read properties of undefined (reading 'filter')
To generate ESM-compatible output, you should use "mts" (for TypeScript ESM) or "ts" (for standard TypeScript). If you specifically need JavaScript ESM output, Prisma does not currently support generating ".mjs" files directly. You would need to transpile the generated TypeScript files to ".mjs" using a separate build step (e.g., with TypeScript or Babel). Here’s a corrected generator block for ESM TypeScript output:
generator client {
provider = "prisma-client"
output = "../src/generated/prisma"
runtime = "nodejs"
moduleFormat = "esm"
generatedFileExtension = "mts" // Use "mts" for ESM TypeScript
importFileExtension = "mts"
}
generator client {
provider = "prisma-client"
output = "../src/generated/prisma"
runtime = "nodejs"
moduleFormat = "esm"
generatedFileExtension = "mts" // Use "mts" for ESM TypeScript
importFileExtension = "mts"
}
If you need ".mjs" files, you must handle the conversion after generation. Prisma does not natively support "mjs" as a generated file extension at this time, and attempting to use it will result in the error you described. For more details, see the Prisma generator field reference and related discussions in the issue tracker here. 🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
Ơ
ƠOP7mo ago
My bad. I've fixed it by myself

Did you find this page helpful?