Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate:types does not work with server-only functions #218

Closed
HarleySalas opened this issue May 15, 2024 · 1 comment
Closed

generate:types does not work with server-only functions #218

HarleySalas opened this issue May 15, 2024 · 1 comment

Comments

@HarleySalas
Copy link

Running payload generate:types does not work when using functions in hooks that have import 'server-only' in them, as for whatever reason, it seems to run functions in a client context during type generation? I would venture to guess that it would not matter where it is ran; anything inside the payload Config would likely see this issue as well.

server-only is a best practice and is commonly used to ensure that functions made to only run on the server are never allowed to run on the client. The error does not trigger in development; so, we know that hooks are running on the server, as they should. However, it is not the case during the generate:types process.

Here is a reproduction.

It's becoming quite taxing (for multiple issues with generate:types now), to have to uncomment many parts of my application, any time that I need to generate:types.

jmikrut added a commit to payloadcms/payload that referenced this issue May 17, 2024
## Description

Allows `server-only` to work within the Payload loader.

Fixes payloadcms/payload-3.0-demo#218
@HarleySalas
Copy link
Author

fixed in #6383/beta.33

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant