From 57408864aa17864cc7f3d67566cb13e70da9d3cc Mon Sep 17 00:00:00 2001 From: Phillip Barta Date: Fri, 16 Jan 2026 16:52:00 +0100 Subject: [PATCH 1/2] fix: use static exports instead of lazy getters Static exports allow Node.js cjs-module-lexer to detect named exports correctly, improving ESM interop and bundler behavior. --- index.js | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index 013ce5c4..c0526e16 100644 --- a/index.js +++ b/index.js @@ -24,41 +24,25 @@ exports = module.exports = bodyParser * JSON parser. * @public */ -Object.defineProperty(exports, 'json', { - configurable: true, - enumerable: true, - get: () => require('./lib/types/json') -}) +exports.json = require('./lib/types/json') /** * Raw parser. * @public */ -Object.defineProperty(exports, 'raw', { - configurable: true, - enumerable: true, - get: () => require('./lib/types/raw') -}) +exports.raw = require('./lib/types/raw') /** * Text parser. * @public */ -Object.defineProperty(exports, 'text', { - configurable: true, - enumerable: true, - get: () => require('./lib/types/text') -}) +exports.text = require('./lib/types/text') /** * URL-encoded parser. * @public */ -Object.defineProperty(exports, 'urlencoded', { - configurable: true, - enumerable: true, - get: () => require('./lib/types/urlencoded') -}) +exports.urlencoded = require('./lib/types/urlencoded') /** * Create a middleware to parse json and urlencoded bodies. From 047691b4a9ae1c01a0a1109762c8bbcef5c9d37a Mon Sep 17 00:00:00 2001 From: Phillip Barta Date: Fri, 16 Jan 2026 16:52:48 +0100 Subject: [PATCH 2/2] feat: add subpath exports for individual parsers Add an exports field to package.json exposing json, raw, text, and urlencoded parsers as subpath exports. This allows consumers to import individual parsers directly: - CommonJS: require('body-parser/json') - ESM: import json from 'body-parser/json' The change is fully backward compatible and enables users to opt into loading only the parsers they need. --- package.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/package.json b/package.json index 486878a2..6b927654 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,14 @@ "type": "opencollective", "url": "https://opencollective.com/express" }, + "exports": { + ".": "./index.js", + "./package.json": "./package.json", + "./json": "./lib/types/json.js", + "./raw": "./lib/types/raw.js", + "./text": "./lib/types/text.js", + "./urlencoded": "./lib/types/urlencoded.js" + }, "dependencies": { "bytes": "^3.1.2", "content-type": "^1.0.5",