payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
24.88k stars 1.58k forks source link

Beta 91 breaks with next.config.ts #7859

Closed iamlinkus closed 3 weeks ago

iamlinkus commented 2 months ago

Link to reproduction

No response

Payload Version

Beta 91

Node Version

21.4.0

Next.js Version

Canary 130

Describe the Bug

After updating from payload beta 90 to 91 without any other changes, when running dev it throws this:

node:internal/modules/cjs/loader:1181
  const err = new Error(`Cannot find module '${request}'`);
              ^        

Error: Cannot find module '.../node_modules/@payloadcms/next/dist/cjs/withPayload.cjs'

Reproduction Steps

  1. pnpm create payload-app@beta
  2. Replace dependencies to use next canary 130 and payload beta 91.
  3. Rename next.config.js to next.config.ts.
  4. pnpm devsafe
  5. Boom.

Reverting to beta 90 and leaving everything else the same fixes the issue.

Adapters and Plugins

No response

tyteen4a03 commented 2 months ago

Scam comment above ^

tyteen4a03 commented 2 months ago

Can you retry with Next canary 104?

Also, do you have "type": "module" in your package.json?

iamlinkus commented 2 months ago

Can you retry with Next canary 107?

Also, do you have "type": "module" in your package.json?

On any version before 91 (and all latest next canaries) everything worked perfectly. Is there a specific reason you want me to try downgrading next? It works when I downgrade payload to 90, and leave next at 130.

Regarding the "type": "module"- no, I don't have that. The create payload app source doesn't either.

tyteen4a03 commented 2 months ago

Until Beta concludes I would recommend sticking to exactly the package versions that Payload's examples specifies: https://github.com/payloadcms/payload-3.0-demo/blob/main/package.json as Next canaries can easily break Payload.

iamlinkus commented 2 months ago

Until Beta concludes I would recommend sticking to exactly the package versions that Payload's examples specifies: https://github.com/payloadcms/payload-3.0-demo/blob/main/package.json as Next canaries can easily break Payload.

I think it's fair to assume that next is not at fault here, since it worked and still works with all the ~2 weeks worth of canaries and the only difference between working and not working is payload version 91 vs 90. I've got at least 4 projects currently in production with canaries higher than the example and closer to the current ones with no issues whatsoever. But this is beside the point, you're commenting on a bug report for a specific case for the latest beta, I don't think "sticking to old versions" to "solve" an issue on a OSS project is helpful, @tyteen4a03, don't you think?

tyteen4a03 commented 2 months ago

I guess I should reword it as Payload can be easily broken by newer Next canaries, which is just an unfortunate fact working with Betas.

There's nothing wrong with the issue, just suggesting sticking to the current versions in case you wanted the problem to go away for you quickly :)

iamlinkus commented 2 months ago

Thanks, @tyteen4a03 , I'm fully aware of the dangers of working with beta/canary software :) As I mentioned in the issue, reverting back to payload beta v90 is how I made the problem go away quickly and will stick to that until this issue resolved.

iamlinkus commented 2 months ago

Just checked, version 95 still has the same problem

w41x commented 2 months ago

I'm having the same issue with Node v22.7.0 PayloadCMS v3.0.0-beta.96 and NextJS v15.0.0-canary.134.

Also I'm using next.config.ts instead of next.config.js.

I solved it by going back to next.config.js. But I think using TypeScript for the next.config file is a good feature (on NextJS side) and should be supported by PayloadCMS!

r1tsuu commented 2 months ago

Try to use .mts extension instead of .ts

iamlinkus commented 2 months ago

Replacing it with .mts extension, I get this:

 ○ Compiling / ...
 ⚠ ./node_modules/.pnpm/mongodb@4.17.1_@aws-sdk+client-sso-oidc@3.637.0/node_modules/mongodb/lib/bson.js
Module not found: Can't resolve 'bson-ext' in '/000-2024/node_modules/.pnpm/mongodb@4.17.1_@aws-sdk+client-sso-oidc@3.637.0/node_modules/mongodb/lib'

Import trace for requested module:
./node_modules/.pnpm/mongodb@4.17.1_@aws-sdk+client-sso-oidc@3.637.0/node_modules/mongodb/lib/bson.js
./node_modules/.pnpm/mongodb@4.17.1_@aws-sdk+client-sso-oidc@3.637.0/node_modules/mongodb/lib/index.js
./node_modules/.pnpm/mongoose@6.12.3_@aws-sdk+client-sso-oidc@3.637.0/node_modules/mongoose/lib/index.js
./node_modules/.pnpm/mongoose@6.12.3_@aws-sdk+client-sso-oidc@3.637.0/node_modules/mongoose/index.js
./node_modules/.pnpm/@payloadcms+db-mongodb@3.0.0-beta.97_@aws-sdk+client-sso-oidc@3.637.0_payload@3.0.0-beta.97/node_modules/@payloadcms/db-mongodb/dist/index.js
./src/payload/payload.config.ts
./src/payload/utilities/getPayload.ts
./src/actions/forms.ts
mvarendorff commented 4 weeks ago

This should be fixed with https://github.com/payloadcms/payload/pull/8521 (included in beta.111)

github-actions[bot] commented 3 weeks ago

This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.