Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@prisma/client/edge + Cloudflare Worker / wrangler = Could not resolve "os" #19174

Closed
zzzej opened this issue May 10, 2023 · 14 comments · Fixed by #19186 or #19195
Closed

@prisma/client/edge + Cloudflare Worker / wrangler = Could not resolve "os" #19174

zzzej opened this issue May 10, 2023 · 14 comments · Fixed by #19186 or #19195
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/regression A reported bug in functionality that used to work before. team/client Issue for team Client. topic: Cloudflare Workers topic: @prisma/client/edge
Milestone

Comments

@zzzej
Copy link

zzzej commented May 10, 2023

Bug description

It was running just fine. I updated prisma and reinstalled dependencies then did npx prisma generate --data-proxy. Generates the client, but right after starting the server with wrangler dev src/index.ts I get
Screenshot 2023-05-10 at 7 11 57 AM

How to reproduce

  1. Run a basic Cloudflare worker wrangler.toml
name = "api"
compatibility_date = "2023-04-19"
  1. Generate prisma with data proxy npx prisma generate --data-proxy
  2. Setup/connect prisma.
  3. Start wrangler wrangler dev src/index.ts
  4. Get error

Expected behavior

Server starts and Prisma edge client works.

Prisma information

import { PrismaClient } from "@prisma/client/edge";

export default function prisma(url: string) {
  const client = new PrismaClient({
    datasources: {
      db: {
        url,
      },
    },
  });

  return client;
}

export type ExtendedPrismaClient = ReturnType<typeof prisma>;
generator client {
  provider = "prisma-client-js"
  previewFeatures = ["clientExtensions", "jsonProtocol"]
  // ALSO TESTED WITH NO PREVIEW FEATURES
}

datasource db {
  provider = "mysql"
  url = env("DATABASE_URL")
  relationMode = "prisma"
}

Environment & setup

  • OS: macOS Apple M2 Pro
  • Database: PlanetScale MySQL
  • Node: 18.16

Prisma Version

4.14
@zzzej zzzej added the kind/bug A reported bug. label May 10, 2023
@zzzej
Copy link
Author

zzzej commented May 10, 2023

Update: It works when I manually set Rp={} instead of Rp=require("os") in edge.js

Before:
Screenshot 2023-05-10 at 7 47 13 AM

After:
Screenshot 2023-05-10 at 7 47 07 AM

@Jolg42 Jolg42 added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. team/client Issue for team Client. topic: Cloudflare Workers topic: @prisma/client/edge topic: cloudflare labels May 10, 2023
@Jolg42
Copy link
Member

Jolg42 commented May 10, 2023

@osejrafael Thanks for this issue! Do you know if this error also happens with a previous version of Prisma, like 4.13.0 or earlier? Maybe this is a recent change 🤔

@zzzej
Copy link
Author

zzzej commented May 10, 2023

@Jolg42 Yes, I tried rolling back to 4.13.0 and I got the same error. Which is weird since that was the only change I made. "Update from 4.13.0 -> 4.14.0 and generate client with --data-proxy"

@alexvuka1
Copy link

I have been using @prisma/client/edge on Vercel Edge (using @astrojs/vercel/edge) and it has been working fine on version 4.13.0, but when I tried updating to 4.14.0 I got the same error as @osejrafael

@oanogin
Copy link

oanogin commented May 10, 2023

I have the same issue with 4.14.0 :/
Workaround 1: replace Rp=require("os") with Rp={} in ../node_modules/@prisma/client/runtime/edge.js (as @osejrafael said couple hours ago)
Workaround 2: add node_compat = true line to wrangler.toml file

@Jolg42
Copy link
Member

Jolg42 commented May 10, 2023

Thanks all! I'll try a reproduction tomorrow, as this looks like an unexpected regression 👀

In the meantime, I can recommend staying on 4.13.0 and stay tuned.

@alexvuka1
Copy link

The file ExitHooks.ts is new in 4.14.0 and it imports os:

Not sure if it is the root of the problem, but might be useful.

@Jolg42
Copy link
Member

Jolg42 commented May 10, 2023

@alexvuka1 Thanks! I also found that this was the most recent addition, potentially that's the problem here.

@millsp
Copy link
Member

millsp commented May 11, 2023

I can confirm I have seen this in the bundled files. We should add a test that no require/import exists in our edge runtime. Currently os imports are not actually required and we could juts blank it out.

@jkomyno jkomyno self-assigned this May 11, 2023
@Jolg42 Jolg42 self-assigned this May 11, 2023
@Jolg42 Jolg42 added this to the 4.15.0 milestone May 11, 2023
@Jolg42 Jolg42 added bug/2-confirmed Bug has been reproduced and confirmed. kind/regression A reported bug in functionality that used to work before. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. labels May 11, 2023
@Jolg42
Copy link
Member

Jolg42 commented May 11, 2023

I got a reproduction in our ecosystem-tests prisma/ecosystem-tests#3508 after updating wrangler
I'll merge my PR for updating our cloudflare worker test, and it will most probably be fixed by #19186 once merged
We'll come back with a confirmation once all testing went through.

@Jolg42
Copy link
Member

Jolg42 commented May 11, 2023

Note: after testing some versions. I can confirm it's a regression that happened in 4.14.0 and it started with 4.14.0-dev.17 which was published after #18900

@Jolg42
Copy link
Member

Jolg42 commented May 11, 2023

Note: confirmed fixed on main branch.
Our internal dev version 4.15.0-dev.13 has the fix and passes the ecosystem-tests

@Jolg42
Copy link
Member

Jolg42 commented May 17, 2023

Note: we are planning an official patch release later today. Stay tuned 😉

@millsp
Copy link
Member

millsp commented May 17, 2023

The fix is now available https://github.com/prisma/prisma/releases/tag/4.14.1. Thanks for the report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/regression A reported bug in functionality that used to work before. team/client Issue for team Client. topic: Cloudflare Workers topic: @prisma/client/edge
Projects
None yet
7 participants