Install it with npm install js-message. Browser module and classic-script use remain available.
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 newerNode 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
typeanddatafields. - The
JSONgetter,toJSON(), andload()returningundefined. - 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.jsbrowser global.