{"id":34048044,"url":"https://github.com/malekabdelkader/rsbuild-plugin-block-imports","last_synced_at":"2026-01-14T20:28:38.733Z","repository":{"id":328378969,"uuid":"1115251431","full_name":"malekabdelkader/rsbuild-plugin-block-imports","owner":"malekabdelkader","description":"Rsbuild plugin to detect and block forbidden imports during build time.","archived":false,"fork":false,"pushed_at":"2025-12-21T16:12:25.000Z","size":56,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-23T05:40:08.726Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/rsbuild-plugin-block-imports","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/malekabdelkader.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-12T15:08:49.000Z","updated_at":"2025-12-21T16:30:44.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/malekabdelkader/rsbuild-plugin-block-imports","commit_stats":null,"previous_names":["malekabdelkader/rsbuild-plugin-block-imports"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/malekabdelkader/rsbuild-plugin-block-imports","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malekabdelkader%2Frsbuild-plugin-block-imports","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malekabdelkader%2Frsbuild-plugin-block-imports/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malekabdelkader%2Frsbuild-plugin-block-imports/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malekabdelkader%2Frsbuild-plugin-block-imports/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/malekabdelkader","download_url":"https://codeload.github.com/malekabdelkader/rsbuild-plugin-block-imports/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malekabdelkader%2Frsbuild-plugin-block-imports/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28434459,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T18:57:19.464Z","status":"ssl_error","status_checked_at":"2026-01-14T18:52:48.501Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-12-14T00:00:51.706Z","updated_at":"2026-01-14T20:28:38.725Z","avatar_url":"https://github.com/malekabdelkader.png","language":"TypeScript","funding_links":[],"categories":["Plugins"],"sub_categories":["Rsbuild Plugins"],"readme":"\n# rsbuild-plugin-block-imports\n\n\u003e Rsbuild plugin to detect and block forbidden imports during build time.\n\u003e \n[![npm version](https://img.shields.io/npm/v/rsbuild-plugin-block-imports.svg)](https://www.npmjs.com/package/rsbuild-plugin-block-imports)\n\n## Why?\n\nSometimes 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:\n\n- `next/link` - Next.js router integration\n- `next/image` - Next.js image optimization\n- `next-intl` - Next.js internationalization\n\nThis plugin scans your source files during build and **fails fast** with actionable error messages, saving you from runtime errors in production.\n\n## Features\n\n- 🔍 **Detects forbidden imports** with exact file:line:column locations\n- 📝 **Shows the actual code** that caused the error\n- 💡 **Suggests alternatives** for each forbidden import\n- 🎨 **Colored terminal output** for better readability\n- ⚙️ **Fully configurable** - add your own patterns\n- 🌳 **Tree-shaking aware** - notes that unused imports are safe\n\n## Installation\n\n```bash\nnpm install rsbuild-plugin-block-imports -D\n# or\npnpm add rsbuild-plugin-block-imports -D\n# or\nyarn add rsbuild-plugin-block-imports -D\n```\n\n## Usage\n\n### Basic Usage (Next.js)\n\n```ts\n// rsbuild.config.ts\nimport { defineConfig } from '@rsbuild/core';\nimport { pluginBlockImports, NEXTJS_FORBIDDEN_IMPORTS } from 'rsbuild-plugin-block-imports';\n\nexport default defineConfig({\n  plugins: [\n    pluginBlockImports({\n      forbiddenImports: NEXTJS_FORBIDDEN_IMPORTS,\n    }),\n  ],\n});\n```\n\n### Custom Forbidden Imports\n\n```ts\nimport { pluginBlockImports } from 'rsbuild-plugin-block-imports';\n\nexport default defineConfig({\n  plugins: [\n    pluginBlockImports({\n      forbiddenImports: [\n        { \n          pattern: 'my-internal-package', \n          alternative: 'Use the public API instead' \n        },\n        { \n          pattern: '@company/server-only', \n          alternative: 'This package is server-side only' \n        },\n      ],\n    }),\n  ],\n});\n```\n\n### Combining with Defaults\n\n```ts\nimport { pluginBlockImports, NEXTJS_FORBIDDEN_IMPORTS } from 'rsbuild-plugin-block-imports';\n\nexport default defineConfig({\n  plugins: [\n    pluginBlockImports({\n      forbiddenImports: [\n        ...NEXTJS_FORBIDDEN_IMPORTS,\n        { pattern: 'my-custom-import', alternative: 'Use X instead' },\n      ],\n    }),\n  ],\n});\n```\n\n## Configuration Options\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `forbiddenImports` | `ForbiddenImport[]` | **required** | Array of forbidden import patterns |\n| `exclude` | `(string \\| RegExp)[]` | `[]` | Paths to exclude from checking |\n| `failOnError` | `boolean` | `true` | Whether to fail the build on errors |\n| `errorHeader` | `string` | `'FORBIDDEN IMPORTS DETECTED'` | Custom header for error output |\n| `colors` | `boolean` | `true` | Enable colored terminal output |\n\n### ForbiddenImport Interface\n\n```ts\ninterface ForbiddenImport {\n  /** Import pattern to match (e.g., 'next/link') */\n  pattern: string;\n  /** Suggested alternative */\n  alternative: string;\n  /** Optional reason why this import is forbidden */\n  reason?: string;\n}\n```\n\n## Example Output\n\n```\n  ╭─────────────────────────────────────────────────────────────╮\n  │  FORBIDDEN IMPORTS DETECTED                                 │\n  ╰─────────────────────────────────────────────────────────────╯\n\n  ✖ Forbidden imports detected in source files\n    These imports are not allowed in the current build context.\n\n  /src/components/MyComponent.tsx:5:0\n    ✖ Forbidden import: next/image\n    │ import Image from 'next/image';\n\n  /src/components/MyComponent.tsx:6:0\n    ✖ Forbidden import: next-intl\n    │ import { useTranslations } from 'next-intl';\n\n  Suggested alternatives:\n    • next/image → \u003cimg src=\"...\"\u003e with proper sizing\n    • next-intl → react-intl, i18next, or react-i18next\n\n  2 error(s) found. Build failed.\n```\n\n## Default Next.js Forbidden Imports\n\nThe `NEXTJS_FORBIDDEN_IMPORTS` export includes:\n\n| Import | Alternative |\n|--------|-------------|\n| `next/link` | `\u003ca href=\"...\"\u003e` or react-router Link |\n| `next/image` | `\u003cimg src=\"...\"\u003e` with proper sizing |\n| `next/router` | `window.location` or custom navigation |\n| `next/navigation` | `window.location` or custom navigation |\n| `next/head` | react-helmet or document.head |\n| `next/script` | `\u003cscript\u003e` tag or useEffect |\n| `next/dynamic` | React.lazy() + Suspense |\n| `next/font` | CSS @font-face or Google Fonts |\n| `next/headers` | Pass headers as props |\n| `next/cookies` | document.cookie or js-cookie |\n| `next-intl` | react-intl or i18next |\n| `next-auth` | Pass auth state as props |\n| `next-themes` | Custom theme context |\n| `next-seo` | react-helmet |\n| `next-i18next` | i18next + react-i18next |\n\n## Tree Shaking Note\n\nIf 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.\n\nHowever, we recommend removing them to prevent accidental usage.\n\nTo disable build failures and only show warnings, set `failOnError: false`.\n\n## License\n\nMIT\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalekabdelkader%2Frsbuild-plugin-block-imports","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmalekabdelkader%2Frsbuild-plugin-block-imports","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalekabdelkader%2Frsbuild-plugin-block-imports/lists"}