Utilities for finding ES module imports, CommonJS requires, and dynamic imports for specific Node.js modules.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/nodejs/userland-migrations/llms.txt
Use this file to discover all available pages before exploring further.
Overview
These utilities help locate module dependencies in different formats:- ES Module Imports:
import fs from 'fs'orimport { readFile } from 'node:fs' - CommonJS Requires:
const fs = require('fs')orconst { readFile } = require('node:fs') - Dynamic Imports:
const fs = await import('fs')
All detection functions automatically support both bare module names (
'fs') and node: prefixed imports ('node:fs').Core Functions
getModuleDependencies
Finds all module import/require statements for a specific Node.js module. This is the most comprehensive function that combines results from all other detection methods.The root AST node to search
The Node.js module name to search for (e.g., ‘fs’, ‘path’, ‘util’)
SgNode<Js>[] - Array of nodes representing all import/require statements for the module
Under the hood, this function calls
getNodeRequireCalls, getNodeImportStatements, and getNodeImportCalls, then combines the results.ES Module Import Detection
getNodeImportStatements
Finds all ES module import statements for a specific Node.js module.The root AST node to search
The Node.js module name to search for
SgNode<Js>[] - Array of import_statement nodes
getNodeImportCalls
Finds dynamic import calls assigned to variables. Excludes unassigned imports.The root AST node to search
The Node.js module name to search for
SgNode<Js>[] - Array of variable_declarator or expression_statement nodes with import calls
This function captures both
const fs = await import('fs') patterns and .then() chained patterns like import('fs').then(...), but ignores simple unassigned import('fs') calls.CommonJS Require Detection
getNodeRequireCalls
Finds CommonJS require calls assigned to variables.The root AST node to search
The Node.js module name to search for
SgNode<Js>[] - Array of variable_declarator nodes with require calls
Simple
require('fs') calls without variable assignment are not captured, as they have no effect in codemod context.