oxc-project/oxc · warning · OxcDiagnostic
'{source}' import is restricted from being used.
Error message
'{source}' import is restricted from being used. What it means
Exact-path restriction from `no-restricted-imports`, reported through `diagnostic_path` WITH a custom help message. It fires when the imported/re-exported module source string exactly matches an entry under the `paths` array that also defines a `message` — the message is attached as the diagnostic's help text.
Source
Thrown at crates/oxc_linter/src/rules/eslint/no_restricted_imports.rs:35
TSModuleReference,
},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use oxc_str::CompactStr;
use crate::{
ModuleRecord,
context::LintContext,
module_record::{ExportEntry, ExportImportName, ImportEntry, ImportImportName, NameSpan},
rule::Rule,
utils::deserialize_required_regex_option,
};
fn diagnostic_with_maybe_help(span: Span, msg: String, help: Option<CompactStr>) -> OxcDiagnostic {
if let Some(help) = help {
return OxcDiagnostic::warn(msg).with_help(help).with_label(span);
}
OxcDiagnostic::warn(msg).with_label(span)
}
fn diagnostic_path(span: Span, help: Option<CompactStr>, source: &str) -> OxcDiagnostic {
let msg = format!("'{source}' import is restricted from being used.");
diagnostic_with_maybe_help(span, msg, help)
}
fn diagnostic_pattern(span: Span, help: Option<CompactStr>, source: &str) -> OxcDiagnostic {
let msg = format!("'{source}' import is restricted from being used by a pattern.");
diagnostic_with_maybe_help(span, msg, help)
}
fn diagnostic_pattern_and_import_name(View on GitHub (pinned to e1e7af627c)
Solutions
- Switch to the replacement named in the help message (e.g. `import map from 'lodash-es/map';`).
- If the import is legitimately required, add an `oxlint-ignore no-restricted-imports` comment with a justification.
- Update the `paths` entry if the restriction is stale (e.g. the module was already replaced).
Example fix
// before import _ from 'underscore'; // after import map from 'lodash-es/map';
Defensive patterns
Strategy: validation
Validate before calling
// Check imports against the restricted list (with guidance) before CI
const RESTRICTED = { 'underscore': 'Use lodash-es instead.', 'moment': 'Use date-fns.' };
for (const m of src.matchAll(/import[\s\S]*?from\s*['"]([^'"]+)['"]/g)) {
if (RESTRICTED[m[1]]) console.error(`${m[1]}: ${RESTRICTED[m[1]]}`);
} Prevention
- Keep the restricted `paths` list in .oxlintrc colocated with dependency-policy docs.
- Add `import/no-restricted` equivalents in editors (VS Code ESLint/oxlint extension) for inline squiggles.
- Use `{ name, message }` entries so every hit is self-explanatory.
When it happens
Trigger: `"no-restricted-imports": ["error", { "paths": [{ "name": "underscore", "message": "Use lodash-es instead." }] }]` plus `import _ from 'underscore';` or `export { x } from 'underscore';` — the module record's import/export entries carry the matched source span.
Common situations: Banning heavy or deprecated dependencies (moment, lodash, internal legacy utils) and pointing developers at the replacement; monorepos enforcing package boundaries via lint.
Related errors
- Reexporting 'default' export is restricted.
- Exporting 'default' is restricted.
- Exporting named value as default is restricted.
- Reexporting named export as default is restricted.
- Reexporting namespace as default is restricted.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/4a5b794e426f13f2.
Report an issue: GitHub.