vercel / next.js

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

Transpile issue in `pnpm build` but not `pnpm dev` in new versions of next.js #55833

Closed alex-statsig closed 6 months ago

alex-statsig commented 1 year ago

Link to the code that reproduces this issue

https://github.com

To Reproduce

When making a production build on nextjs 13.5.2 (updated from 13.4.8), an error occurs on an API route. Interestingly this error does not appear during pnpm dev (only pnpm build && pnpm start). This makes me thing there is a bug in local package transpilation (the error is occurring in a snippet coming from a local pnpm package that had no issue before updating / when using pnpm dev).

{"status":"error","time":1695401300423.652,"err":{"type":"TypeError","message":"Invalid schema configuration: `S` is not a valid type at path `source_id`. See https://bit.ly/mongoose-schematypes for a list of valid schema types.","stack":"TypeError: Invalid schema configuration: `S` is not a valid type at path `source_id`. See https://bit.ly/mongoose-schematypes for a list of valid schema types.\n    at Schema.interpretAsType (/Users/alex/dev/statsig/node_modules/.pnpm/mongoose@7.0.0/node_modules/mongoose/lib/schema.js:1403:11)\n    at Schema.path (/Users/alex/dev/statsig/node_modules/.pnpm/mongoose@7.0.0/node_modules/mongoose/lib/schema.js:1026:27)\n    at Schema.add (/Users/alex/dev/statsig/node_modules/.pnpm/mongoose@7.0.0/node_modules/mongoose/lib/schema.js:745:14)\n    at new Schema (/Users/alex/dev/statsig/node_modules/.pnpm/mongoose@7.0.0/node_modules/mongoose/lib/schema.js:134:10)\n    at Object.54055 (/Users/alex/dev/statsig/intern/.next/server/chunks/9674.js:1:7979)\n    at o (/Users/alex/dev/statsig/intern/.next/server/webpack-api-runtime.js:1:128)\n    at Object.98087 (/Users/alex/dev/statsig/intern/.next/server/chunks/9674.js:1:1465)\n    at o (/Users/alex/dev/statsig/intern/.next/server/webpack-api-runtime.js:1:128)\n    at Object.54124 (/Users/alex/dev/statsig/intern/.next/server/chunks/5750.js:1:148354)\n    at o (/Users/alex/dev/statsig/intern/.next/server/webpack-api-runtime.js:1:128)"},"msg":"Invalid schema configuration: `S` is not a valid type at path `source_id`. See https://bit.ly/mongoose-schematypes for a list of valid schema types."}

I'm not sure how to cleanly reproduce this, but I don't think a production-breaking issue like this should be ignored.

Current vs. Expected behavior

Would expect there to not be a production crash in this case (a local package seems to be webpacked incorrectly)

Verify canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.6.0: Wed Jul  5 22:22:52 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T8103
    Binaries:
      Node: 16.17.1
      npm: 8.15.0
      Yarn: 1.22.19
      pnpm: 7.32.4
    Relevant Packages:
      next: 13.5.2
      eslint-config-next: N/A
      react: 18.1.0
      react-dom: 18.1.0
      typescript: 4.8.4
    Next.js Config:
      output: N/A

Note: Also tried on 13.5.3-canary.1

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

Middleware / Edge (API routes, runtime)

Additional context

I will try to create a simple reproduction, but as this is a production-breaking issue it seems appropriate to file the issue first and try to reproduce better myself after

alex-statsig commented 1 year ago

I can confirm this is caused by serverMinification being enabled, which was made the default in https://github.com/vercel/next.js/pull/54960. cc @feedthejim

github-actions[bot] commented 6 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.