prisma: `prisma generate` fails in Deno Fresh project, `error: Uncaught ReferenceError: module is not define`
Bug description
following the official docs for integrating Prisma with Deno everything works other than generating docs.
the prisma folder, schema.prisma, .env, .gitignore were all created and changed accordingly to the documentation.
when I used npx to generate the files it worked but then deno could not find the correct file to import PrismaClient from.
The following error is produced. I do not know why it is attempting to look for a node_modules folder inside of a Deno Fresh Project.
error: Uncaught ReferenceError: module is not defined
module.exports = __toCommonJS(generator_exports);
^
at file:///C:/Users/User/node_modules/@prisma/client/generator-build/index.js:15188:1
How to reproduce
follow the prisma deploy to deno documentation
Expected behavior
the files to be generated as they would using npm or npx
Prisma information
<!-- Do not include your database credentials when sharing your Prisma schema! -->
generator client {
provider = "prisma-client-js"
previewFeatures = ["deno"]
output = "../generated/client"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model Shipment {
id Int @id @default(autoincrement())
createdAt DateTime @updatedAt
updatedAt DateTime @updatedAt
planet String
hazardous Boolean
animal Boolean
fragile Boolean
oversize Boolean
description String
cost Int
email String
name String
}
enum Level {
Info
Warn
Error
}
// Add your code using Prisma Client
Environment & setup
Windows 11 PlanetScale Deno 1.36.0 (release, x86_64-pc-windows-msvc) v8 11.6.189.12 typescript 5.1.6 JetBrains Pycharm Pro 2023.2
Prisma Version
5.1.0
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 2
- Comments: 16 (8 by maintainers)
Hello everyone, may I inquire if there is a solution to this issue? I am currently using Hono for testing and have encountered the same problem.
However, it’s peculiar that this issue only occurs in the development environment, while everything functions normally after deployment.
Here is the reference tutorial: https://developers.cloudflare.com/d1/tutorials/d1-and-prisma-orm/
Below is the code to reproduce the issue.
I’m setting up Prisma on a new project with Deno/Oak and am getting the same error when I run the command
deno run -A npm:prisma@^5.4.1 generateIt gives this error:
It creates a
package.jsonand node_modules folder but does not generate the prisma client in the location specified in myschema.prisma:Update: I ran the command a second time (I didn’t delete the node modules) and it did generate the client.
Now I have another problem: when I try to use the Prisma client, I get:
It looks like it is expecting me to use the data proxy, however I only want to connect to a local database.
This is also mentioned in this issue: https://github.com/prisma/prisma/issues/2452
In my code I also tried just importing the prisma client npm package:
but this also did would not run:
I tried to reproduce this:
And indeed I get a similar error to what you posted:
Somehow I have all these
Downloadmessages in there as well 😕Understood, thank you.
Sorry that I ddin’t explain it well.
deno run -A npm:prisma@^5.2 generate --data-proxyfailed to generated prisma client code due to the error:I tried to remove the
generator-build/index.js(including the whole node_modules/) and rerun the command multiple times and it keeps throwing the same error.My workaround is to use
npx prisma@^5.2 generate --data-proxyinstead, but I will need to remove the!!globalThis.Denoinnode_modules/@prisma/client/generator-build/index.jsto generate deno client.The error is happening when attempting the command
deno run -A --unstable npm:prisma generate --data-proxyto make the generated directory It also happens after the db push command when prisma tries to generate documents on it’s own, then tells me the flags I can use next time to skip the generate step.This occurred on a new deno fresh project as well as the original deno fresh project I was originally using Prisma for.
The other Prisma commands work (push, pull, studio, format, etc…)
EDIT: when making a project starting with Prisma it will generate, but attempting to add Prisma to the project after it has been created is causing the weird problem when generating.
creating a project folder, prisma init, prisma push and generate, then creating the fresh app works. adding prisma to an existing Fresh project (even on a completely new scaffold) is where I am finding the bug.