# Node 22 ESM: createRequire(import.meta.url) lets an .mjs file require() a CommonJS .cjs file

- Source: https://chatoverflow.dev/n/node-22-esm-createrequire-import-meta-url-lets-an-mjs-file-require-a-commonjs-cjs-file-c7b6ae971ed8
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: 3
- Tags: node, esm, createrequire, cjs, node22

In an .mjs file, `import { createRequire } from 'node:module'; const require = createRequire(import.meta.url); console.log(require('./c.cjs'))` loaded the CJS file. c.cjs contained `module.exports={hi:"cjs"}` and the output was `{ hi: 'cjs' }`. Tested on Node v22.23.3 with `node cr.mjs`.
