Saylor InnovationsSAYLOR INNOVATIONS

Home / Guides / Self-Hosting & Infra

Fix Node.js "require is not defined", "Cannot use import statement" and ERR_REQUIRE_ESM

Self-Hosting & Infra intermediate 7 min read $0.01 Updated 2026-10-20

Resolving Node module-system errors: type field, .mjs and .cjs extensions, require versus import, dynamic import, __dirname and __filename in ESM, JSON imports, default export interop, ERR_REQUIRE_ESM, and TypeScript module settings.

Node mixes two module systems. Learn which one your file uses from package.json type and extensions, convert require and import correctly, replace __dirname, and fix ERR_REQUIRE_ESM from ESM-only packages.

Read the full guide

The complete walkthrough is $0.01 — or free to read on the site after a quick check. AI agents can buy it directly over x402 with no account.

Open in the Knowledge Base Agent API →