oxc-project/oxc · warning · OxcDiagnostic
Do not mix core, module, file and computed requires.
Error message
Do not mix core, module, file and computed requires.
What it means
Diagnostic from oxlint rule node/no-mixed-requires, emitted only when the grouping option is true. It requires each declaration to contain requires of a single kind: core modules (the BUILTIN_MODULES list frozen at Node v13.8.0 — fs, path, events...), file modules (specifiers starting with './', '../' or '/'), package modules (other string literals), or computed requires (non-literal or absent argument, e.g. require(getName())). Mixing kinds in one statement is the reported offense.
Source
Thrown at crates/oxc_linter/src/rules/node/no_mixed_requires.rs:23
AstKind,
ast::{Expression, VariableDeclarator},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use crate::{
AstNode,
context::LintContext,
rule::{DefaultRuleConfig, Rule},
};
fn no_mix_require_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Do not mix 'require' and other declarations.").with_label(span)
}
fn no_mix_core_module_file_computed_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Do not mix core, module, file and computed requires.").with_label(span)
}
#[derive(Debug, Default, Clone, Copy, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase", deny_unknown_fields, default)]
struct NoMixedRequiresOptions {
grouping: bool,
allow_call: bool,
}
#[derive(Debug, Clone, Deserialize, JsonSchema)]
#[serde(untagged)]
enum NoMixedRequiresConfig {
Grouping(bool),
Options(NoMixedRequiresOptions),
}
#[derive(Debug, Default, Clone, Deserialize, JsonSchema)]
pub struct NoMixedRequires(NoMixedRequiresOptions);View on GitHub (pinned to e1e7af627c)
Solutions
- Group declarations by require kind: builtins together, relative files together, packages together, computed last
- Prefer one require per line so grouping is explicit and diff-friendly
- If the convention isn't worth the churn, set "grouping": false (the default) and only the mixing check remains
Example fix
// before (grouping: true)
var fs = require('fs'),
async = require('async'),
myUtils = require('./utils');
// after: grouped by kind
var fs = require('fs');
var async = require('async');
var myUtils = require('./utils'); Defensive patterns
Strategy: validation
Validate before calling
// .oxlintrc.json
"rules": {
"node/no-mixed-requires": ["error", { "grouping": true, "allowCall": false }]
}
npx oxlint -c .oxlintrc.json --deny-warning . Prevention
- Order requires consistently (built-ins, then packages, then relative files) so grouping violations stand out in review
- Remember the builtin list is frozen at Node v13.8.0 — modern specifiers like 'node:fs' count as package requires under this rule
- Adopt one-require-per-line style; explicit grouping then comes free
When it happens
Trigger: Config "node/no-mixed-requires": ["error", { "grouping": true }] or the boolean shorthand ["error", true], plus a single declaration containing requires classified into two or more module types — e.g. var fs = require('fs'), foo = require('./foo'); (core + file) or var foo = require('foo'), bar = require(getName()); (module + computed). The base mixing check must NOT have fired first (it returns early), so the statement is all-requires but heterogeneous.
Common situations: Strict style configs inherited from eslint-plugin-n; legacy files where requires were appended in whatever order over years; caveat: the builtin list is dated, so modern specifiers like 'node:fs' or 'fs/promises' classify as 'module', not core.
Related errors
- Unexpected require().
- Do not mix 'require' and other declarations.
- Split requires to be separated into a single block.
- Unexpected access to `exports`.
- Unexpected access to `module.exports`.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/69bc2fb8c74c7ce1.
Report an issue: GitHub.