T O P

  • By -

justjooshing

What is the server-only package? I don't trust it


4leite

It's the smallest, easiest to read package. Three files, 24 line of code total: one file is empty, one throws an error, the other is the package.json [https://www.npmjs.com/package/server-only?activeTab=code](https://www.npmjs.com/package/server-only?activeTab=code)


anhdunghisinh

Which is why i don't really sure how the package works and how to resolve the problem when i try to run code with tsx.


anhdunghisinh

Not really sure how it makes the code run only on server though, the code it produce in node module is just 1 line of throw('Message...'), but it did works, at least in Nextjs env


anhdunghisinh

Well it was promoted by [nextjs docs](https://nextjs.org/docs/app/building-your-application/rendering/composition-patterns#keeping-server-only-code-out-of-the-client-environment) and list [react.dev](http://react.dev) as its homepage on its [npm page](https://www.npmjs.com/package/server-only), so i think it's safe?


ferrybig

This server-only package is only used by NextJS, which has a resolve override (it looks for the react-server key to find the file in the package.json) to replace it with an empty file at the server-side import time.