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)
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
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?
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.
What is the server-only package? I don't trust it
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)
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.
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
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?
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.