How to publish an NPM package with server actions in it?
Unanswered
Sun bear posted this in #help-forum
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 bear 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.
in the actual built file, does it have use server (ie is your builder removing it), or is nextjs just not picking up on it (kinda sad but makes sense)
@Sun bear 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.
where did you put the "use server"?
at the top of a file?
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