Skip to content

nodejs/package.cjs.json

@repobuddy/typescript/nodejs/package.cjs.json is a package.json fragment that sets "type": "commonjs". Copy it into a CommonJS build’s output folder as package.json.

{
"type": "commonjs"
}

The package exports it under ./nodejs/*, so you can resolve it by name:

Terminal window
node -e "console.log(require.resolve('@repobuddy/typescript/nodejs/package.cjs.json'))"

Two commands copy it for you:

  • Node.js reads .js files by the type field of the nearest package.json. In a package whose root package.json has "type": "module", a cjs/package.json with "type": "commonjs" makes Node.js load the .js files under cjs/ as CommonJS.
  • The file has no other fields, so it does not change the package’s name, version, or exports.