oxc-project/oxc · warning

Imported module should be assigned

Error message

Imported module should be assigned

What it means

This is the oxlint 'import/no-unassigned-imports' diagnostic. The rule fires when an ES module import has no import specifiers at all (e.g. import 'foo'), because such imports are only useful for their side effects. The linter flags them unless the module source matches one of the 'allow' glob patterns in the rule config. It exists because unassigned imports hide whether a module is actually needed, make tree-shaking and mocking harder, and can accidentally pull in heavyweight dependencies.

Source

Thrown at crates/oxc_linter/src/rules/import/no_unassigned_import.rs:103

    version = "0.16.11",
    short_description = "This rule aims to remove modules with side-effects by reporting when a module is imported but not assigned.",
);

impl Rule for NoUnassignedImport {
    fn from_configuration(value: Value) -> Result<Self, serde_json::error::Error> {
        DefaultRuleConfig::<Self>::from_value(value).map(DefaultRuleConfig::into_inner)
    }

    fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
        match node.kind() {
            AstKind::ImportDeclaration(import_decl) => {
                if import_decl.specifiers.is_some() {
                    return;
                }
                if !self.is_match_allow_globs(import_decl.source.value.as_str()) {
                    ctx.diagnostic(no_unassigned_import_diagnostic(
                        import_decl.span,
                        "Imported module should be assigned",
                    ));
                }
            }
            AstKind::ExpressionStatement(statement) => {
                let Expression::CallExpression(call_expr) = &statement.expression else {
                    return;
                };
                if !call_expr.is_require_call() {
                    return;
                }
                let first_arg = &call_expr.arguments[0];
                let Argument::StringLiteral(source_str) = first_arg else {
                    return;
                };
                if !self.is_match_allow_globs(source_str.value.as_str()) {
                    ctx.diagnostic(no_unassigned_import_diagnostic(
                        call_expr.span,
                        "A `require()` style import is forbidden.",

View on GitHub (pinned to e1e7af627c)

Solutions

  1. If the import is genuinely unused, delete the import statement.
  2. If you need a value from the module, assign it: import fs from 'fs' or import * as tokens from './tokens'.
  3. If the import is intentionally side-effectful (CSS, polyfills), add it to the rule's allow globs in .oxlintrc.json: "import/no-unassigned-imports": ["error", { "allow": ["**/*.css", "core-js/**"] }].
  4. If side-effect imports are an accepted pattern in the project, disable the rule with an inline oxlint-disable comment or turn it off in the config.

Example fix

// before
import './styles.css';
import 'should';

// after (allowed via config)
// .oxlintrc.json: "import/no-unassigned-imports": ["error", { "allow": ["**/*.css"] }]
import './styles.css';
import should from 'should';
Defensive patterns

Strategy: validation

Validate before calling

# fail fast in CI before linting, listing side-effect imports not on the allow list
rg -n "^\s*import\s+['\"][^'\"]+['\"]" src/ --glob '!*.css'

Prevention

When it happens

Trigger: Run oxlint with the import/no-unassigned-imports rule enabled on a file containing an ImportDeclaration whose specifiers field is None (bare 'import "source";') where the source string does not match any configured allow glob. The diagnostic is emitted on the import statement's span.

Common situations: Teams adopt this rule to ban side-effect imports, then hit it on CSS/style imports (import './index.css'), polyfill imports (import 'core-js/stable'), and framework bootstrap files (import './app.css'). The default config has an empty allow list, so every side-effect import is reported until globs are added.

Related errors


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