Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
server-cli-only
Advanced tools
The server-cli-only package is designed to restrict the import of modules exclusively to React Server Components or scripts running on the CLI.
This package is designed as a failsafe. All modules marked with import "server-cli-only"
will throw an error on build-time if imported into a module running in the "browser" runtime (e.g., React Client Components). This package is an alternative to the server-only
package, which permits the execution of React Server Components runtimes but doesn't allow using other server or edge runtimes. This package aims for the use with React but can also be used in other projects that follow this strategy.
npm i server-cli-only
Import server-cli-only
at the beginning of a module that you want to protect from leaking to the front-end (browser):
import "server-cli-only";
Now, imports of your module importing server-cli-only
into "browser" modules (e.g., React Client Components) will throw an error.
You can directly execute scripts in server runtimes like node
, deno
, and bun
. For example:
node your-script.js
Or in your package.json
:
{
"scripts": {
"your-cli-script": "node your-script.js"
}
}
This package tries to align with the guidelines in the React Server Module Conventions of RFC #227 but extends this guideline to also allow executions in other server and edge runtimes, not only the "react-server" runtime. The overarching goal is to restrict modules with sensitive data from being leaked to the front-end (browser) by using "conditional exports" in Node.js's package.json
file. Doing so results in build-time errors for "browser" and unknown runtime modules. Following, all allowed and forbidden (error-throwing) runtimes.
Key | Target |
---|---|
react-server | React Server Components |
node | Node.js runtime |
bun | Bun runtime |
deno | Deno runtime |
edge-light | Vercel edge |
netlify | Netlify edge |
workerd | Cloudflare edge |
Key | Target |
---|---|
browser | React Client Components |
<unknown> | All unknown runtimes |
Proposed Specs concerning the different runtime keys available by the Web-interoperable Runtimes Community Group (WinterCG). And React-DOM's package.json "conditional exports" field.
MIT License.
FAQs
The server-cli-only package is designed to restrict the import of modules exclusively to React Server Components or scripts running on the CLI.
The npm package server-cli-only receives a total of 1,254 weekly downloads. As such, server-cli-only popularity was classified as popular.
We found that server-cli-only demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.