vercel / next.js

The React Framework
https://nextjs.org
MIT License
124.76k stars 26.63k forks source link

[turbopack] Bug with prisma client 5.5.2 "Error resolving commonjs request" #57601

Closed biohackerellie closed 5 months ago

biohackerellie commented 10 months ago

Link to the code that reproduces this issue

https://github.com/laurel-public-schools/lps-facilities

To Reproduce

{
  "name": "front-end",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "preinstall": "npx only-allow pnpm",
    "postinstall": "prisma generate --no-engine",
    "dev": "next dev --turbo",
    "build": "next build",
    "start": "next start",
    "lint": "next lint",
    "test": "jest"
  },
  "dependencies": {
    "@emotion/react": "^11.11.1",
    "@google-cloud/local-auth": "^2.1.1",
    "@hookform/error-message": "^2.0.1",
    "@hookform/resolvers": "^3.3.1",
    "@next-auth/prisma-adapter": "^1.0.6",
    "@prisma/client": "^5.5.2",
    "@prisma/extension-accelerate": "^0.6.2",
    "@radix-ui/colors": "^0.1.8",
    "@radix-ui/react-alert-dialog": "^1.0.4",
    "@radix-ui/react-checkbox": "^1.0.4",
    "@radix-ui/react-dialog": "^1.0.4",
    "@radix-ui/react-dropdown-menu": "^2.0.5",
    "@radix-ui/react-hover-card": "^1.0.6",
    "@radix-ui/react-icons": "^1.3.0",
    "@radix-ui/react-label": "^2.0.2",
    "@radix-ui/react-navigation-menu": "^1.1.3",
    "@radix-ui/react-popover": "^1.0.7",
    "@radix-ui/react-scroll-area": "^1.0.4",
    "@radix-ui/react-select": "^2.0.0",
    "@radix-ui/react-separator": "^1.0.3",
    "@radix-ui/react-slot": "^1.0.2",
    "@radix-ui/react-switch": "^1.0.3",
    "@radix-ui/react-tabs": "^1.0.4",
    "@radix-ui/react-toast": "^1.1.5",
    "@radix-ui/react-tooltip": "^1.0.6",
    "@tanstack/react-table": "^8.9.7",
    "@types/react": "^18.2.6",
    "@types/react-dom": "18.2.4",
    "@vercel/analytics": "^1.0.2",
    "autoprefixer": "10.4.14",
    "bcrypt": "^5.1.0",
    "bcryptjs": "^2.4.3",
    "class-variance-authority": "^0.6.1",
    "clsx": "^1.2.1",
    "cmdk": "^0.2.0",
    "dotenv": "^16.1.4",
    "encoding": "^0.1.13",
    "eslint": "8.40.0",
    "eslint-config-next": "13.5.1",
    "googleapis": "^118.0.0",
    "jsonwebtoken": "^9.0.2",
    "lucide-react": "^0.274.0",
    "minio": "^7.1.1",
    "moment": "^2.29.4",
    "moment-timezone": "^0.5.43",
    "multer": "1.4.5-lts.1",
    "next": "14.0.0",
    "next-auth": "^4.24.3",
    "next-themes": "^0.2.1",
    "npm": "^9.6.7",
    "postcss": "8.4.23",
    "react": "^18.2.0",
    "react-big-calendar": "^1.6.9",
    "react-calendar": "^4.2.1",
    "react-datepicker": "^4.12.0",
    "react-dom": "^18.2.0",
    "react-google-calendar-api": "^2.2.2",
    "react-hook-form": "^7.46.2",
    "react-hot-toast": "^2.4.1",
    "react-icons": "^4.8.0",
    "react-modal": "^3.16.1",
    "react-select": "^5.7.3",
    "react-square-web-payments-sdk": "^3.2.1",
    "square": "^28.0.1",
    "styled-components": "^6.0.0-rc.3",
    "sweetalert2": "^11.7.11",
    "sweetalert2-react-content": "^5.0.7",
    "tailwind-merge": "^1.14.0",
    "tailwind-scrollbar": "^3.0.4",
    "tailwindcss": "3.3.2",
    "tailwindcss-animate": "^1.0.7",
    "zod": "^3.22.2"
  },
  "devDependencies": {
    "@ellreka/tailwindcss-nth-child": "^1.0.1",
    "@tailwindcss/forms": "^0.5.3",
    "@tailwindcss/typography": "^0.5.9",
    "@types/bcrypt": "^5.0.0",
    "@types/bcryptjs": "^2.4.2",
    "@types/jsonwebtoken": "^9.0.2",
    "@types/multer": "^1.4.7",
    "@types/node": "^20.4.9",
    "@types/nodemailer": "^6.4.8",
    "@types/react-big-calendar": "^1.6.3",
    "@types/react-datepicker": "^4.11.2",
    "@types/react-modal": "^3.16.0",
    "argon2": "^0.30.3",
    "eslint-config-prettier": "^8.8.0",
    "jest": "^29.6.2",
    "prisma": "^5.5.2",
    "typescript": "5.2.2"
  }
}
// src/lib/prisma.ts

import { PrismaClient } from '@prisma/client/edge';
import { withAccelerate } from '@prisma/extension-accelerate';

const prisma = new PrismaClient().$extends(withAccelerate());

export default prisma;

Any page that makes a prisma query produces the same result

// src/app/facilities/page.tsx
import React from 'react';
import SubNav from '@/components/ui/subNav';
import { Suspense } from 'react';
import FacilityCardSkeleton from '@/components/ui/skeletons/CardSkeleton';
import FacilityCard from './facility_card';

async function getFacilities() {
    const res = await fetch(process.env.NEXT_PUBLIC_HOST + '/api/facilities');
    const facilities = await res.json();
    return facilities;
}

export default async function FacilitiesPage() {
    const facilities = await getFacilities();
return( 
...
// src/api/facilities/route
import { NextResponse } from 'next/server';
import prisma from '@/lib/prisma';
import { serializeJSON } from '@/utils/serializeJSON';

export const runtime = 'edge';

export async function GET(request: Request) {
  const res = await prisma.facility.findMany({
    include: {
      Category: true,
    },
    cacheStrategy: { swr: 3600, ttl: 3600 },
  });
  return NextResponse.json(serializeJSON(res));
}

Current vs. Expected behavior

creates this issue

 ⚠ /api/users/[id] error - [project]/node_modules/.pnpm/@prisma+client@5.5.2_prisma@5.5.2/node_modules/@prisma/client/runtime/edge.js - Error resolving commonjs request
unable to resolve module "https"

 error - node_modules/.pnpm/@prisma+client@5.5.2_prisma@5.5.2/node_modules/@prisma/client/runtime/edge.js:28:727
  Error resolving commonjs request

26 | In Cloudflare module Workers, environment variables are available only in the Worker's \`env\`
parameter of \`fetch\`.

27 | To solve this, provide the connection string directly: https://pris.ly/d/cloudflare-datasource-url`,n):new 
re(`error: Environment variable not found: ${s.fromEnvVar}.`,n);if(o===void 0)throw new re("error: Missing URL
 nvironment variable, value, or override.",n);return o}d();p();f();d();p();f();var Ln=class extends Error{constructor(r,n
{super(r);this.clientVersion=n.clientVersion,this.cause=n.cause}get[Symbol.toStringTag](){return this.name}};var we=class extends 
 Ln{constructor(r,n){var o;super(r,n);this.isRetryable=(o=n.isRetryable)!=null?o:!0}};d();p();f();d();p();f();
function q(e,t)

Verify canary release

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP Mon Aug 7 19:01:48 UTC 2023
Binaries:
  Node: 18.17.1
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.7.6
Relevant Packages:
  next: 14.0.0
  eslint-config-next: 13.5.1
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

App Router, Turbopack (--turbo)

Additional context

No response

PACK-1954

dancamdev commented 10 months ago

Does not seem to be strictly related to Prisma more details below.

unable to resolve dynamic

 error - node_modules/.pnpm/node-gyp-build@4.6.1/node_modules/node-gyp-build/node-gyp-build.js:22:10  Error resolving commonjs request

  20 |
  21 | function load (dir) {
> 22 |   return runtimeRequire(load.resolve(dir))
     |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 23 | }
     | ^
  24 |
  25 | load.resolve = load.path = function (dir) {
  26 |   dir = path.resolve(dir || '.')
unable to resolve dynamic
It was not possible to find the requested file.
    Parsed request as written in source code: dynamic
    Path where resolving has started: [project]/node_modules/.pnpm/node-gyp-build@4.6.1/node_modules/node-gyp-build/node-gyp-build.js
    Type of request: commonjs request
    Import map: No import map entry
rendaardy commented 10 months ago

Does not seem to be strictly related to Prisma more details below.

unable to resolve dynamic

 error - node_modules/.pnpm/node-gyp-build@4.6.1/node_modules/node-gyp-build/node-gyp-build.js:22:10  Error resolving commonjs request

  20 |
  21 | function load (dir) {
> 22 |   return runtimeRequire(load.resolve(dir))
     |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 23 | }
     | ^
  24 |
  25 | load.resolve = load.path = function (dir) {
  26 |   dir = path.resolve(dir || '.')
unable to resolve dynamic
It was not possible to find the requested file.
    Parsed request as written in source code: dynamic
    Path where resolving has started: [project]/node_modules/.pnpm/node-gyp-build@4.6.1/node_modules/node-gyp-build/node-gyp-build.js
    Type of request: commonjs request
    Import map: No import map entry

I also got this error when I'm following tutorial "Learn Next.js" in https://nextjs.org/learn specifically in chapter 7 using next dev --turbo

theonlydaleking commented 10 months ago

FWIW I came here from an error when using supabase. I would say this adds to the evidence that this is unrelated to external packages supabase/supabase#17586

ForsakenHarmony commented 10 months ago

@dancamdev that's a different issue, not directly related

would appreciate it if you could open a separate issue for it

github-actions[bot] commented 7 months ago

We cannot easily recreate the issue with the provided information. Please add a minimal reproduction in order for us to be able to help more efficiently.

Why was this issue marked with the please simplify reproduction label?

There was a reproduction provided, but due to its complexity, we cannot easily reproduce the issue.

An ideal minimal reproduction (unless relevant):

In general, assume that we should not go through a lengthy onboarding process at your company code only to be able to verify an issue.

If you cannot create a clean reproduction, another way you can help the maintainers' job is to pinpoint the canary version of next that introduced the issue. Check out our releases, and try to find the first canary release that introduced the issue. This will help us narrow down the scope of the issue, and possibly point to the PR/code change that introduced it. You can install a specific version of next by running npm install next@<version>.

What happens if I don't provide a sufficient minimal reproduction?

Issues with the please simplify reproduction label that receive no meaningful activity (e.g. new comments with a simplified reproduction link) are automatically closed and locked after 30 days.

If your issue has not been resolved in that time and it has been closed/locked, please open a new issue with the required reproduction.

I did not open this issue, but it is relevant to me, what can I do to help?

Anyone experiencing the same issue is welcome to provide a minimal reproduction following the above steps.

I think my reproduction is good enough, why aren't you looking into it quicker?

We look into every Next.js issue and constantly monitor open issues for new comments.

However, sometimes we might miss one or two due to the popularity/high traffic of the repository. We apologize, and kindly ask you to refrain from tagging core maintainers, as that will usually not result in increased priority.

Providing a minimal reproduction from the start without asking helps us look into issues much more quickly, as we can easily verify if the reported bug is related to Next.js. That said, every issue is important to us, and if an issue gets closed by accident, we encourage you to open a new one linking to the old issue and we will look into it.

Useful Resources

balazsorban44 commented 5 months ago

This issue has been automatically closed because it received no activity for over a month and had no reproduction to investigate. If you think it was closed by accident, please leave a comment. If you are running into a similar issue, please open a new issue with a reproduction. Thank you.

github-actions[bot] commented 5 months ago

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.