Next.js Discord

Discord Forum

How to publish an NPM package with server actions in it?

Unanswered
Sun bear posted this in #help-forum
Open in Discord
Sun bearOP
Is it possible to publish an NPM package that contains server actions? I've tried to do it and then import that library in my NextJS project and use the action, but it seems like the "use server" directive is just ignored and the "server" code gets executed on the client.

7 Replies

Sun bearOP
the builder is removing it
@aardani where did you put the "use server"?
Sun bearOP
Yeah at the top
@Sun bear Yeah at the top
try putting "use server" in each function at the top of each function body
Sun bearOP
yeah I tried that as well, it still ships the code in the client bundle with the directive in there and then runs on the client