oxc-project/oxc · warning

Usage of namespaced aka wildcard \"*\" imports prohibited

Error message

Usage of namespaced aka wildcard \"*\" imports prohibited

What it means

Diagnostic from the oxlint rule import/no-namespace (style category). It fires on wildcard imports: `import * as ns from 'mod'`. Namespace imports pull the whole module into one binding, which prevents tree-shaking in bundlers, obscures which members are used, and (for CJS interop) behaves differently across bundlers. The config accepts `ignore`: an array of globs for modules that may be namespace-imported (e.g. `["*.json"]`).

Source

Thrown at crates/oxc_linter/src/rules/import/no_namespace.rs:17

use fast_glob::glob_match;

use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use oxc_str::CompactStr;
use schemars::JsonSchema;
use serde::Deserialize;

use crate::{
    context::LintContext,
    module_record::ImportImportName,
    rule::{DefaultRuleConfig, Rule},
};

fn no_namespace_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Usage of namespaced aka wildcard \"*\" imports prohibited")
        .with_help("Use named or default imports")
        .with_label(span)
}

#[derive(Debug, Default, Clone, Deserialize)]
pub struct NoNamespace(Box<NoNamespaceConfig>);

#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct NoNamespaceConfig {
    /// An array of glob strings for modules that should be ignored by the rule.
    /// For example, `["*.json"]` will ignore all JSON imports.
    ignore: Vec<CompactStr>,
}

impl std::ops::Deref for NoNamespace {
    type Target = NoNamespaceConfig;

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Import only what you use: `import { debounce } from './utils'` or the default export
  2. Add legitimate exceptions to the ignore globs: `{ "ignore": ["*.json", "cjs-lib"] }`
  3. For side-effect ordering or dynamic member access by name, replace with explicit named imports generated from a list

Example fix

// before
import * as utils from './utils';
utils.debounce(fn, 100);

// after
import { debounce } from './utils';
debounce(fn, 100);
Defensive patterns

Strategy: validation

Validate before calling

// .oxlintrc.json
{ "rules": { "import/no-namespace": ["warn", { "ignore": ["*.json"] }] } }

Prevention

When it happens

Trigger: Any ImportNamespaceSpecifier whose module request does not match an `ignore` glob — reported via no_namespace_diagnostic at crates/oxc_linter/src/rules/import/no_namespace.rs:17. Typical: `import * as lodash from 'lodash'`, `import * as utils from './utils'`, `import * as data from './data.json'` (the JSON case unless ignored).

Common situations: Migrating from `const x = require('x')` habits; JSON/CJS-only modules with no named exports; performance reviews where namespace imports were found to bloat bundles.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/902eb0dc36e51481. Report an issue: GitHub.