linters/eslint-rules/no-dynamic-node-builtin-import
ESLint rule: no-dynamic-node-builtin-import
Reports a dynamic import() of a Node builtin - import('node:child_process'), or a bare builtin name such as import('fs/promises') - in a plugin’s shipped source. A plugin is bundled as CommonJS with the builtins external, and esbuild then leaves such an import() as a native dynamic import in main.js, rather than turning it into a require(). Obsidian’s renderer cannot load a node: (or bare builtin) specifier through import(), so the code fails only when the call runs, and a catch around it turns the failure into silence: a desktop git runner shipped that way lost every git rename it was meant to record.
The working shape is a static import in a desktop- module, which esbuild compiles to a require() that Obsidian’s desktop renderer resolves, reached from the cross-platform caller through a Platform.isDesktopApp-gated dynamic import() of that module. The specifier is read when it is a string literal, or a template literal without substitutions; a computed specifier is left alone. Tests are not linted by it: they run in Node, where the import works.
Variables
Section titled “Variables”| Variable | Description |
|---|---|
| MESSAGE_ID | Message ID reported for a dynamic import of a Node builtin. |
| noDynamicNodeBuiltinImport | ESLint rule forbidding a dynamic import() of a Node builtin in plugin source. |