Fix
Root cause: await import("@ast-grep/napi") uses ESM module resolution, which does NOT respect NODE_PATH or Module._initPaths(). Those only affect CJS require() calls. This is why v3.7.12-v3.7.14 all failed despite correctly setting NODE_PATH.
Solution: Use createRequire() from Node.js module package to create a CJS-style require function that respects NODE_PATH. Falls back to dynamic import for pure ESM environments.
Resolution chain:
- Banner sets
NODE_PATH→Module._initPaths()(CJS paths updated) getSgModule()usescreateRequire().require("@ast-grep/napi")(CJS resolution, respects NODE_PATH)- Fallback to
import()if CJS fails (pure ESM environments)