vercel / next.js

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

App Directory produced dependencies (MongoDB) warnings #48282

Closed wouter-deen closed 1 year ago

wouter-deen commented 1 year ago

Verify canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000
    Binaries:
      Node: 16.13.2
      npm: 9.6.4
      Yarn: 1.22.19
      pnpm: N/A
    Relevant packages:
      next: 13.3.0
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true)

To Reproduce

I seem to have the exact same issue as this: https://github.com/vercel/next.js/issues/42277. However, this issue should have been resolved a while back. I'm running the most up-to-date version of NextJS (at the time of writing) and somehow, I still seem to get the same problem. The issue seems to be specifically happening in my Activity Mongoose model (all my other models don't produce this issue):

import {Model, Schema, Types} from "mongoose";
import createModel from "../createModel";
import {Lesson} from "@/database/models/lesson.model";

export enum ActivityType {
  CONTENT = "CONTENT",
  QUIZ = "QUIZ",
  VIDEO = "VIDEO",
  CHECKLIST = "CHECKLIST",
  SUBMISSION = "SUBMISSION",
  INTRODUCTION = "INTRODUCTION",
  FILES = "FILES"
}

export interface Activity {
  _id: Types.ObjectId;
  displayName: string;
  content: string;
  type: string | ActivityType,

  lesson: Types.Subdocument<Types.ObjectId> & Lesson;
  //files: Types.DocumentArray<File>;
}

type ActivityModel = Model<Activity, {}>;

const activitySchema = new Schema<Activity, ActivityModel>({
  displayName: String,
  content: String,
  type: {type: String, required: true},

  lesson: { type: Schema.Types.ObjectId, ref: "lesson", required: true },
}, {
  timestamps: true
});

export default createModel<Activity, ActivityModel>("activity", activitySchema);

I am posting this here instead of in the Mongoose or MongoDB repos, since it seems very likely that this is a bug with NextJS rather than those, given the linked issue above.

Describe the Bug

Please refer to linked issue for more info. This is my log:

warn  - ./node_modules/mongodb/lib/deps.js
Module not found: Can't resolve 'kerberos' in '/Users/wouterdeen/Documents/Programming/heatwaves/node_modules/mongodb/lib'

Import trace for requested module:
./node_modules/mongodb/lib/deps.js
./node_modules/mongodb/lib/index.js
./node_modules/mongoose/lib/index.js
./node_modules/mongoose/index.js
./lib/api/database/models/activity.model.ts
./components/Lesson/Modals/EditActivityModal.tsx
./components/Lesson/ActivityCard.tsx
./app/(lessonLayout)/lesson/[lessonId]/activity/[activityId]/activity-page.tsx

./node_modules/mongodb/lib/deps.js
Module not found: Can't resolve '@mongodb-js/zstd' in '/Users/wouterdeen/Documents/Programming/heatwaves/node_modules/mongodb/lib'

Import trace for requested module:
./node_modules/mongodb/lib/deps.js
./node_modules/mongodb/lib/index.js
./node_modules/mongoose/lib/index.js
./node_modules/mongoose/index.js
./lib/api/database/models/activity.model.ts
./components/Lesson/Modals/EditActivityModal.tsx
./components/Lesson/ActivityCard.tsx
./app/(lessonLayout)/lesson/[lessonId]/activity/[activityId]/activity-page.tsx

./node_modules/mongodb/lib/deps.js
Module not found: Can't resolve '@aws-sdk/credential-providers' in '/Users/wouterdeen/Documents/Programming/heatwaves/node_modules/mongodb/lib'

Import trace for requested module:
./node_modules/mongodb/lib/deps.js
./node_modules/mongodb/lib/index.js
./node_modules/mongoose/lib/index.js
./node_modules/mongoose/index.js
./lib/api/database/models/activity.model.ts
./components/Lesson/Modals/EditActivityModal.tsx
./components/Lesson/ActivityCard.tsx
./app/(lessonLayout)/lesson/[lessonId]/activity/[activityId]/activity-page.tsx

./node_modules/mongodb/lib/deps.js
Module not found: Can't resolve 'snappy' in '/Users/wouterdeen/Documents/Programming/heatwaves/node_modules/mongodb/lib'

Import trace for requested module:
./node_modules/mongodb/lib/deps.js
./node_modules/mongodb/lib/index.js
./node_modules/mongoose/lib/index.js
./node_modules/mongoose/index.js
./lib/api/database/models/activity.model.ts
./components/Lesson/Modals/EditActivityModal.tsx
./components/Lesson/ActivityCard.tsx
./app/(lessonLayout)/lesson/[lessonId]/activity/[activityId]/activity-page.tsx

./node_modules/mongodb/lib/utils.js
Critical dependency: the request of a dependency is an expression

Import trace for requested module:
./node_modules/mongodb/lib/utils.js
./node_modules/mongodb/lib/change_stream.js
./node_modules/mongodb/lib/index.js
./node_modules/mongoose/lib/index.js
./node_modules/mongoose/index.js
./lib/api/database/models/activity.model.ts
./components/Lesson/Modals/EditActivityModal.tsx
./components/Lesson/ActivityCard.tsx
./app/(lessonLayout)/lesson/[lessonId]/activity/[activityId]/activity-page.tsx

./node_modules/mongodb/lib/utils.js
Module not found: Can't resolve 'mongodb-client-encryption' in '/Users/wouterdeen/Documents/Programming/heatwaves/node_modules/mongodb/lib'

Import trace for requested module:
./node_modules/mongodb/lib/utils.js
./node_modules/mongodb/lib/change_stream.js
./node_modules/mongodb/lib/index.js
./node_modules/mongoose/lib/index.js
./node_modules/mongoose/index.js
./lib/api/database/models/activity.model.ts
./components/Lesson/Modals/EditActivityModal.tsx
./components/Lesson/ActivityCard.tsx
./app/(lessonLayout)/lesson/[lessonId]/activity/[activityId]/activity-page.tsx

Expected Behavior

The pages work fine, but they are very slow (compared to other pages that don't use MongoDB/Mongoose for data fetching). Also, building with Vercel gives me a lot of errors (missing dependencies).

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

Vercel

JesseKoldewijn commented 1 year ago

Hey man @ijjk I saw you were really active on the previous issues regarding this same behavior. Do you know if there were any changes that might have broken the previous fix for this issue by chance?

Ps. srry for pinging, just saw your name drop by a lot in the previous issues where the issue was the same behavior. 💯

wouter-deen commented 1 year ago

I identified the problem to be that Mongoose doesn't handle enums well. When changing the enum to a type in my model and changing some code, it works fine. I will update my issue on the Mongoose repo accordingly and close this issue. For anyone that has the same problem, see this issue: https://github.com/Automattic/mongoose/issues/13261.

eric-burel commented 1 year ago

Well this enum things is still very surprising. I currently still see the missing modules seen on this issue while adding "mongo" to severComponentsExternalPackages option

@ijjk I couldn't comment on #42277 but I am not sure the "serverComponentsExternalPackages" config is enough in all situations. It doesn't seem to work for me, perhaps because I use pnpm, I still have issues with mongo

Here are my logs (extremely hard to build a minimal repro sorry, I am suing 13.4):

Import trace for requested module:
../node_modules/.pnpm/@aws-sdk+util-user-agent-node@3.306.0/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
../node_modules/.pnpm/@aws-sdk+util-user-agent-node@3.306.0/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/index.js
../node_modules/.pnpm/@aws-sdk+client-cognito-identity@3.306.0/node_modules/@aws-sdk/client-cognito-identity/dist-cjs/runtimeConfig.js
../node_modules/.pnpm/@aws-sdk+client-cognito-identity@3.306.0/node_modules/@aws-sdk/client-cognito-identity/dist-cjs/CognitoIdentityClient.js
../node_modules/.pnpm/@aws-sdk+client-cognito-identity@3.306.0/node_modules/@aws-sdk/client-cognito-identity/dist-cjs/index.js
../node_modules/.pnpm/@aws-sdk+credential-providers@3.306.0/node_modules/@aws-sdk/credential-providers/dist-cjs/fromCognitoIdentity.js
../node_modules/.pnpm/@aws-sdk+credential-providers@3.306.0/node_modules/@aws-sdk/credential-providers/dist-cjs/index.js
../node_modules/.pnpm/mongodb@5.4.0_k6g22hirxxolmpmmi2eqykttpy/node_modules/mongodb/lib/deps.js
../node_modules/.pnpm/mongodb@5.4.0_k6g22hirxxolmpmmi2eqykttpy/node_modules/mongodb/lib/index.js
../shared/mongo/mongo.ts
../shared/mongo/index.ts

This perhaps the import is not correctly matched as something corresponding to "mongodb" NPM package?

github-actions[bot] commented 1 year ago

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