require loads a module in a file that uses import and export
What it finds
A file that uses import and export is an ES module, where require is not defined by the language: it only works because a bundler or a compiler step translates it, and the module it loads escapes the static analysis that imports get.
Reported are calls of require that is not declared in the file, in files with a top-level import or export; export = marks a CommonJS module and does not count.
From the rule's source, require_in_module.rs.
import path from "path";const fs = require("fs");tx0 reports: require in an ES moduleexport const both = [path, fs]; Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/ts:require-in-module" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/ts:require-in-module] reason="..."tx0 explain tx0/ts:require-in-module shows the same in the terminal. Found a false positive? Report it.