{"success":true,"name":"pick-the-node-js-module-system-deliberately-esm-vs-commonjs","description":"Starting a Node.js project or hitting import/require errors.","category":"ai-brimind","path":"ai-brimind/pick-the-node-js-module-system-deliberately-esm-vs-commonjs/SKILL.md","file":"SKILL.md","content":"---\nname: pick-the-node-js-module-system-deliberately-esm-vs-commonjs\ndescription: \"Starting a Node.js project or hitting import/require errors.\"\n---\n\n# Pick the Node.js Module System Deliberately (ESM vs CommonJS)\n\n## When to use\nProject is Node.js, and you are creating a new project, adding \"type\": \"module\", or seeing errors like ERR_REQUIRE_ESM or 'Cannot use import statement'.\n\n## Example request\n'Cannot use import statement outside a module' → package.json lacks \"type\": \"module\" or the file isn't .mjs — the module system is a project-level setting, not a per-file mood. require() of an ESM-only package crashes → some packages ship ESM only; CommonJS can't require them — check the package's docs before mixing. __dirname is undefined in ESM → ESM has no __dirname; use import.meta.url — same need, different built-in. Mixing import and require in one file → pick one system per project — this is the dual-package hazard.\n\n## Instructions\nAct as a Node.js developer who settles the module system BEFORE writing imports. First check package.json: does it declare \"type\": \"module\" (ESM) or default to CommonJS? Then check the key dependencies: are any ESM-only or CommonJS-only? Classify the project: new projects should generally choose ESM; existing CommonJS projects should stay consistent unless a migration is planned deliberately. Never fix an import error by randomly swapping import/require syntax until it runs — that treats the symptom. Know the equivalents: __dirname/__filename become import.meta.url + fileURLToPath in ESM; dynamic import() works in both. If a dependency conflicts with the chosen system, check its docs for a compatible entry point before writing a workaround. Only write code once the module system is confirmed and consistent, and explain why the chosen system matches both the project setting and the dependencies.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #981\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}