npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

unplugin-deny-imports

v0.1.5

Published

Deny imports with full import trace support for Vite, Bun, Rollup, webpack, and esbuild

Downloads

13

Readme

unplugin-deny-imports

Deny imports with full import trace support. Works with Vite, Bun, Rollup, webpack, and esbuild.

Features

  • Full Import Trace - See the complete import chain, not just the immediate importer
  • Multi-Bundler Support - Works with Vite, Bun, Rollup, webpack, and esbuild
  • Batteries-Included Presets - 200+ server-only packages blocked out of the box
  • Directive Enforcement - Automatically enforces "use server" / "use client" directives
  • Pattern Matching - Glob patterns and RegExp support for flexible rules

Why?

When a server-only import leaks into client code, you need to know how it got there:

🚫 Import Denied
🌐 client  ·  pattern: drizzle-orm
────────────────────────────────────────
  1. ❌ drizzle-orm
  2. src/lib/api.ts
  3. src/routes/index.tsx (entry)
────────────────────────────────────────

Install

npm install unplugin-deny-imports
# or
bun add unplugin-deny-imports

Quick Start

Vite

import denyImports from 'unplugin-deny-imports/vite'
import preset from 'unplugin-deny-imports/presets'

export default defineConfig({
  plugins: [
    denyImports(preset),
  ],
})

Bun

import denyImports from 'unplugin-deny-imports/bun'
import preset from 'unplugin-deny-imports/presets'

await Bun.build({
  entrypoints: ['./src/index.ts'],
  plugins: [denyImports({ ...preset, target: 'client' })],
})

Custom Rules

import denyImports from 'unplugin-deny-imports/vite'

export default defineConfig({
  plugins: [
    denyImports({
      client: {
        specifiers: [/@app\/.*\/server$/],
        files: ['**/*.server.ts'],
      },
      server: {
        specifiers: ['react-dom/client'],
      },
      ignoreImporters: [/\.test\.ts$/],
    }),
  ],
})

Extend the Preset

import denyImports from 'unplugin-deny-imports/vite'
import { preset } from 'unplugin-deny-imports/presets'

export default defineConfig({
  plugins: [
    denyImports(preset({
      exclude: ['drizzle-orm'],  // Remove from defaults
      client: {
        specifiers: [/@app\/.*\/server$/],  // Add to defaults
      },
    })),
  ],
})

Default Preset

The preset blocks common server-only code from client and vice versa:

Client denies:

  • Node.js built-ins (fs, path, crypto, node:*, etc.)
  • Bun built-ins (bun:*)
  • Databases & ORMs (pg, drizzle-orm, prisma, mongodb, redis, etc.)
  • Server frameworks (express, fastify, hono, koa, etc.)
  • Auth (bcrypt, jsonwebtoken, lucia, passport, etc.)
  • Email (nodemailer, resend, @sendgrid/*, etc.)
  • File & storage (sharp, @aws-sdk/*, multer, etc.)
  • Queues (bullmq, pg-boss, etc.)
  • Payments (stripe, etc.)
  • Testing (vitest, jest, playwright, etc.)
  • Server file conventions (**/*.server.*, **/.server/**)

Server denies:

  • react-dom/client
  • Client-only packages (framer-motion, localforage, etc.)
  • Client file conventions (**/*.client.*, **/.client/**)

Options

| Option | Type | Default | Description | | ------------------- | ---------------------- | --------- | -------------------------------------------------- | | client.specifiers | (string \| RegExp)[] | - | Deny these import specifiers in client | | client.files | (string \| RegExp)[] | - | Deny files matching patterns in client | | server.specifiers | (string \| RegExp)[] | - | Deny these import specifiers in server | | server.files | (string \| RegExp)[] | - | Deny files matching patterns in server | | ignoreImporters | (string \| RegExp)[] | - | Skip if chain includes these files | | maxDepth | number | 15 | Max depth for import trace | | directives | boolean | true | Enforce "use server" / "use client" | | target | 'client' \| 'server' | - | Build target for Bun/esbuild | | mode | 'error' \| 'warn' | 'error' | Throw or log warnings | | stack | boolean | false | Show JS stack trace in errors |

Directive Enforcement

Files with "use server" directives are automatically blocked from client bundles:

// actions.ts
"use server"  // ← Blocked from client imports

export async function createUser() { ... }

Note: "use client" is NOT enforced - these components are valid in SSR (they mark the React Server Component boundary, not "never run on server").

Disable with:

denyImports({ directives: false })

Pattern Types

  • Strings: Glob patterns via micromatch
  • RegExp: Full regex support

Bundler Support

| Feature | Vite | Bun | Rollup | webpack | esbuild | | ----------------- | :--: | :-: | :----: | :-----: | :-----: | | Specifier denial | ✅ | ✅ | ✅ | ✅ | ✅ | | File path denial | ✅ | ✅ | ⚠️ | ⚠️ | ⚠️ | | Full import trace | ✅ | ✅ | ✅ | ✅ | ✅ | | SSR detection | ✅ | ✅* | ❌ | ❌ | ❌ | | HMR cleanup | ✅ | - | - | - | - |

⚠️ = Limited (requires absolute paths) * = Via target option

Credits

Inspired by vite-env-only by Pedro Cattori.

Built with unplugin by the UnJS team.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

MIT