Skip to content

chore: add CommonJS export and main; bump version to 1.1.2#1323

Closed
parirox wants to merge 2 commits into
yagop:masterfrom
parirox:chore/cjs-export
Closed

chore: add CommonJS export and main; bump version to 1.1.2#1323
parirox wants to merge 2 commits into
yagop:masterfrom
parirox:chore/cjs-export

Conversation

@parirox

@parirox parirox commented Jun 23, 2026

Copy link
Copy Markdown
  • All unit tests pass (npm run test:node:unit)
  • All integration tests pass (npm run test:node:integration)
  • npm run typecheck is clean
  • doc/api.md is up to date (bun run generate:docs leaves no diff — required when a TelegramBot method signature changed)

Description

Adds a CommonJS build entry (./dist/index.cjs) and a require condition to the exports field, so the package works as a dual ESM/CJS module. Also sets main to the CJS build for legacy tooling compatibility and bumps the version to 1.1.2.

This unblocks NestJS users and any other CJS consumer (e.g. Jest with default config) from upgrading to v1, who currently hit ERR_PACKAGE_PATH_NOT_EXPORTED at runtime.

References


Running the test suite

...

yagop commented Jun 24, 2026

Copy link
Copy Markdown
Owner

Thanks for tackling #1322. The current change is not enough yet because it only advertises a CommonJS entry, but does not actually build one.

package.json now points both main and the exports.require condition at ./dist/index.cjs, but the build script is still just tsc -p tsconfig.build.json. With the current tsconfig (module: NodeNext, root package type: module), that emits dist/index.js and declarations, not dist/index.cjs.

I verified this on the PR branch:

npm ci
npm pack --dry-run
node -e "require('node-telegram-bot-api')"

The packed files include dist/index.js, but no dist/index.cjs, and the require() check fails with:

Cannot find module '/tmp/ntba-pr1323/dist/index.cjs'

So CommonJS users would still be broken, just with MODULE_NOT_FOUND instead of ERR_PACKAGE_PATH_NOT_EXPORTED.

The fix needs to generate a real CJS artifact and test it. Two reasonable options:

  1. Use a dual-package build tool such as zshy, which emits both index.js and index.cjs.
  2. Keep tsc and add a second CJS build, for example to dist/cjs, with a nested package.json containing { "type": "commonjs" }, then point exports.require at that file.

If we are okay with CommonJS consumers using either of these shapes:

const { TelegramBot } = require('node-telegram-bot-api');
// or
const TelegramBot = require('node-telegram-bot-api').default;

then no compatibility wrapper is needed. But the README example in this PR should use one of those forms instead of const TelegramBot = require(...).

Also, since the PR bumps package.json to 1.1.2, package-lock.json should be updated too; it still reports 1.1.1 for the root package.

@yagop

yagop commented Jun 25, 2026

Copy link
Copy Markdown
Owner

Closed by #1325

@yagop yagop closed this Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v1 ESM-only migration breaks CJS consumers (NestJS, Jest, etc.)

3 participants