Replies: 8 comments 14 replies
|
Answer to myself: NB: |
|
Hey @M1CK431, the new
The statement is true for Prisma 6, as The idea is that the generated Prisma Client files become part of your own codebase, rather than being hidden within I'd always recommend bundling your app in production, but if you want to run Prisma locally without compiling TypeScript to JavaScript, and without using |
|
Hi @jkomyno , thanks for your reply.
Does it means
From official documentation, regardless of where the client files are generated, they will never really become part of my own codebase since they have to be excluded from Git. So no real difference compared to being generated in
Why? What's the benefit compared to A last side note, despite I'm not so attached to terminology in most cases, Typescript can't be "compiled" to Javascript. The correct term is "transpilation" (Yes, I know you know it because you use that term too earlier in your reply). IMHO it' very important for people to understand that Javascript stands by itself. TypeScript might be useful is some cases as a DX enhancement, but at runtime, it doesn't even exist. Anyway, thank you for your insights. I appreciate your clarification. |
|
@M1CK431 I have a solution that is a bit weird, but it does an amazing job required npm packages: tsconfig.prisma.json {
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "Node",
"outDir": "./generated/prisma",
"rootDir": "./generated/prisma-ts",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"strict": false,
"declaration": true,
"resolveJsonModule": true,
},
"include": ["./generated/prisma-ts"]
}Prisma Schema settings: generator client {
provider = "prisma-client"
output = "../generated/prisma-ts"
importFileExtension = "js" // Essential since your tsc conversion cannot change imports
}package json script "generateClient": "npx prisma generate && tsc --project tsconfig.prisma.json",example import import { PrismaClient } from '../generated/prisma/client.js'
const prisma = new PrismaClient()This works pretty fine IMO, everything worked without any issues, I did testing with my current project and the supertest passed, and I have like 100 custom things on top of Prisma, including custom extensions, and nothing said "I do not like it" It is a better alternative to |
|
Update for people who will see this Node.js now officially supports TypeScript as of v25.2.0, so you do not need our implementation; you can just directly run the ts files from js files now. I have tested it and no complaints |
|
@xxsuperdreamxx Not yet since Prisma client may generate TS enum (depending of your schema) and so |
|
After Prisma CLI complained for a few weeks that I should upgrade to v7, I finally decided to tackle this migration. I open the guide, follow the instructions, and oh at some point I need to import ts files but my project is in JavaScript. That doesn't work (I just use bare NodeJS on the backend).
Three things:
Some people are using Prisma in production for years with a huge JavaScript codebase. You can't ask those people to migrate their 50,000 files to TypeScript, or to switch to Bun. That's not serious. TL;DR:
|
|
It doesn't work with vanilla js natively but you still could build your project. If you don't know how to work with typescript here's a small instruction:
package.json: "scripts": {
"dev": "tsx watch --clear-screen=false app.js",
"build": "tsup index.js --format esm --clean --minify",
"start": "node dist/index.js",
"serve": "pnpm build && pnpm start"
}, |
Uh oh!
There was an error while loading. Please reload this page.
Bug description
As stated on the official Prisma website, both Javascript (aka "vanilla") and TypeScript are supported languages.
However, while trying
prisma-clientprovider withgeneratedFileExtension = "js", generated files are still using TypeScript (despite.jsextension) and so can't be used in vanilla JS files.Severity
🔹 Minor: Unexpected behavior, but does not block development
Reproduction
Not relevant
Expected vs. Actual Behavior
Expected:
generatedFileExtension = "js"should generate vanilla JS filesActual: TypeScript files with
.jsgeneratedFrequency
Consistently reproducible
Does this occur in development or production?
Both development and production
Is this a regression?
No since related to an "Early Access" feature.
Workaround
Remain on
prisma-client-jsproviderPrisma Schema & Queries
Not relevant.
Prisma Config
Not relevant
Logs & Debug Info
Not relevant
Environment & Setup
Prisma Version
From
package.json:{ "prisma": "^6.10.1" "@prisma/adapter-better-sqlite3": "^6.10.1", "@prisma/client": "^6.10.1", }All reactions