Migration to 3.1

One module. Both Node syntaxes.

Version 3.1 raises the runtime floor to Node 22.13, lets import and require() share one constructor, and restores optional message fields.

Version 3.1.1 requires Node.js 22.13 or newer.

Install it with npm install js-message. Browser module and classic-script use remain available.

js-message works with bundlers and without a bundler.

Bundlers resolve the bare js-message import normally. Native browser ESM resolves it through a standard import map, with no build or transpilation step.

Raise the Node.js floor

Update production, CI, containers, and local development to Node 22.13 or newer before installing 3.1.

node --version
# v22.13.0 or newer

Node 22.13 is the first 22.x release where synchronous require(ESM) no longer emits an experimental warning by default.

Choose syntax, not a separate build

import Message from 'js-message';
const Message = require('js-message');

Both entries resolve to the synchronous Message.js source and return the same constructor identity. js-message/index.js and js-message/Message.js remain supported direct paths.

Keep incomplete messages incomplete

Version 3.0 accidentally required both message keys. Version 3.1 restores the original assignment behavior:

const ping = new Message('{"type":"ping"}');

ping.type === 'ping';
ping.data === undefined;
ping.JSON === '{"type":"ping"}';

type, data, or both may be absent. Add application-level validation only where your own protocol requires it.

What stays compatible

  • Mutable, enumerable type and data fields.
  • The JSON getter, toJSON(), and load() returning undefined.
  • Buffer, boxed-string, typed-view, and custom JSON-coercible text input.
  • Recoverable malformed-input messages with serializable error details.
  • The explicit js-message/js-message-vanilla.js browser global.