You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using custom endpoints, the official docs say to use NextResponse to send the response object, which is imported from next/server.
However, doing this prevents the payload generate:types command from running due to next/server not being found.
> cross-env NODE_OPTIONS=--no-deprecation payload "generate:types"
node:internal/process/promises:289
triggerUncaughtException(err, true /* fromPromise */);
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/<path/to/project>/node_modules/next/server' imported from /<path/to/project/endpoint-function.ts>`Did you mean to import next@14.2.0-canary.10_react-dom@18.2.0_react@18.2.0/node_modules/next/server.js? at finalizeResolution (node:internal/modules/esm/resolve:264:11) at moduleResolve (node:internal/modules/esm/resolve:917:10) at defaultResolve (node:internal/modules/esm/resolve:1130:11) at nextResolve (node:internal/modules/esm/hooks:865:28) at resolve (file:///<path/to/project>/node_modules/.pnpm/payload@3.0.0-alpha.48_@swc+core@1.4.7_@swc+types@0.1.5/node_modules/payload/dist/bin/register/index.js:59:12) at nextResolve (node:internal/modules/esm/hooks:865:28) at Hooks.resolve (node:internal/modules/esm/hooks:303:30) at handleMessage (node:internal/modules/esm/worker:196:24) at Immediate.checkForMessages [as _onImmediate] (node:internal/modules/esm/worker:138:28) at process.processImmediate (node:internal/timers:478:21) { code: 'ERR_MODULE_NOT_FOUND', url: 'file:///<path/to/project>/node_modules/next/server'}
To Reproduce
Create a custom endpoint in a collection and use NextResponse in the handler.
// some collectionendpoints: [{path: '/route/:param',method: 'get',
handler,},],
Using Response instead of NextResponse in the handler function does not cause this error. Also, using NextResponse within a custom route file, like the one in the alpha demo, does not cause this error either.
As a side note, destructuring the http-status was causing a syntax error when generating types only, but I checked the source and the aliases are exported. Not sure if it could be related.
// SyntaxError: The requested module 'http-status' does not provide an export named 'OK'import{OK}from'http-status';// But this is fineimportHttpStatusfrom'http-status';Response.json(someResponse,{status: HttpStatus.OK});
Link to reproduction
No response
Describe the Bug
When using custom endpoints, the official docs say to use NextResponse to send the response object, which is imported from
next/server
.However, doing this prevents the
payload generate:types
command from running due tonext/server
not being found.To Reproduce
Create a custom endpoint in a collection and use
NextResponse
in the handler.Payload Version
3.0.0-alpha.48
Adapters and Plugins
"@payloadcms/db-mongodb": "3.0.0-alpha.48", "@payloadcms/next": "3.0.0-alpha.48", "@payloadcms/plugin-cloud-storage": "3.0.0-alpha.48", "@payloadcms/plugin-nested-docs": "3.0.0-alpha.48", "@payloadcms/richtext-lexical": "3.0.0-alpha.48",
The text was updated successfully, but these errors were encountered: