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

rsbuild-plugin-block-imports

v1.0.1

Published

Rsbuild plugin to detect and block forbidden imports during build time

Readme

rsbuild-plugin-block-imports

Rsbuild plugin to detect and block forbidden imports during build time.

npm version

Why?

Sometimes certain imports should not be used in specific contexts. For example, when using Module Federation to expose React components from a Next.js application, certain imports won't work in remote environments:

  • next/link - Next.js router integration
  • next/image - Next.js image optimization
  • next-intl - Next.js internationalization

This plugin scans your source files during build and fails fast with actionable error messages, saving you from runtime errors in production.

Features

  • 🔍 Detects forbidden imports with exact file:line:column locations
  • 📝 Shows the actual code that caused the error
  • 💡 Suggests alternatives for each forbidden import
  • 🎨 Colored terminal output for better readability
  • ⚙️ Fully configurable - add your own patterns
  • 🌳 Tree-shaking aware - notes that unused imports are safe

Installation

npm install rsbuild-plugin-block-imports -D
# or
pnpm add rsbuild-plugin-block-imports -D
# or
yarn add rsbuild-plugin-block-imports -D

Usage

Basic Usage (Next.js)

// rsbuild.config.ts
import { defineConfig } from '@rsbuild/core';
import { pluginBlockImports, NEXTJS_FORBIDDEN_IMPORTS } from 'rsbuild-plugin-block-imports';

export default defineConfig({
  plugins: [
    pluginBlockImports({
      forbiddenImports: NEXTJS_FORBIDDEN_IMPORTS,
    }),
  ],
});

Custom Forbidden Imports

import { pluginBlockImports } from 'rsbuild-plugin-block-imports';

export default defineConfig({
  plugins: [
    pluginBlockImports({
      forbiddenImports: [
        { 
          pattern: 'my-internal-package', 
          alternative: 'Use the public API instead' 
        },
        { 
          pattern: '@company/server-only', 
          alternative: 'This package is server-side only' 
        },
      ],
    }),
  ],
});

Combining with Defaults

import { pluginBlockImports, NEXTJS_FORBIDDEN_IMPORTS } from 'rsbuild-plugin-block-imports';

export default defineConfig({
  plugins: [
    pluginBlockImports({
      forbiddenImports: [
        ...NEXTJS_FORBIDDEN_IMPORTS,
        { pattern: 'my-custom-import', alternative: 'Use X instead' },
      ],
    }),
  ],
});

Configuration Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | forbiddenImports | ForbiddenImport[] | required | Array of forbidden import patterns | | exclude | (string \| RegExp)[] | [] | Paths to exclude from checking | | failOnError | boolean | true | Whether to fail the build on errors | | errorHeader | string | 'FORBIDDEN IMPORTS DETECTED' | Custom header for error output | | colors | boolean | true | Enable colored terminal output |

ForbiddenImport Interface

interface ForbiddenImport {
  /** Import pattern to match (e.g., 'next/link') */
  pattern: string;
  /** Suggested alternative */
  alternative: string;
  /** Optional reason why this import is forbidden */
  reason?: string;
}

Example Output

  ╭─────────────────────────────────────────────────────────────╮
  │  FORBIDDEN IMPORTS DETECTED                                 │
  ╰─────────────────────────────────────────────────────────────╯

  ✖ Forbidden imports detected in source files
    These imports are not allowed in the current build context.

  /src/components/MyComponent.tsx:5:0
    ✖ Forbidden import: next/image
    │ import Image from 'next/image';

  /src/components/MyComponent.tsx:6:0
    ✖ Forbidden import: next-intl
    │ import { useTranslations } from 'next-intl';

  Suggested alternatives:
    • next/image → <img src="..."> with proper sizing
    • next-intl → react-intl, i18next, or react-i18next

  2 error(s) found. Build failed.

Default Next.js Forbidden Imports

The NEXTJS_FORBIDDEN_IMPORTS export includes:

| Import | Alternative | |--------|-------------| | next/link | <a href="..."> or react-router Link | | next/image | <img src="..."> with proper sizing | | next/router | window.location or custom navigation | | next/navigation | window.location or custom navigation | | next/head | react-helmet or document.head | | next/script | <script> tag or useEffect | | next/dynamic | React.lazy() + Suspense | | next/font | CSS @font-face or Google Fonts | | next/headers | Pass headers as props | | next/cookies | document.cookie or js-cookie | | next-intl | react-intl or i18next | | next-auth | Pass auth state as props | | next-themes | Custom theme context | | next-seo | react-helmet | | next-i18next | i18next + react-i18next |

Tree Shaking Note

If a forbidden import is present in a file but not actually used in the exposed components, webpack's tree-shaking algorithm will remove it from the final bundle. This means it won't cause runtime errors.

However, we recommend removing them to prevent accidental usage.

To disable build failures and only show warnings, set failOnError: false.

License

MIT