Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
RPCServer
✓ import { RPCServer } from 'ocpp-rpc'
✗ const RPCServer = require('ocpp-rpc').RPCServer
ESM named import; CommonJS require works but does not destructure.
RPCClient
✓ import { RPCClient } from 'ocpp-rpc'
✗ const ocpp = require('ocpp-rpc'); const client = new ocpp.RPCClient({...});
Use named import for clarity, but CommonJS require works with destructuring.
createRPCError
✓ import { createRPCError } from 'ocpp-rpc'
✗ import createRPCError from 'ocpp-rpc'
Default export is the module itself; use named export.
Sets up a minimal OCPP1.6J server with authentication and a BootNotification handler.
import { RPCServer, createRPCError } from 'ocpp-rpc';
const server = new RPCServer({
protocols: ['ocpp1.6'],
strictMode: true,
});
server.auth((accept, reject, handshake) => {
accept({ sessionId: 'XYZ123' });
});
server.on('client', async (client) => {
console.log(`${client.session.sessionId} connected!`);
client.on('request', async (request) => {
if (request.action === 'BootNotification') {
return {
status: 'Accepted',
currentTime: new Date().toISOString(),
interval: 300,
};
}
throw createRPCError('NotImplemented');
});
client.on('error', (err) => {
console.error('Client error:', err);
});
client.on('disconnect', (code, reason) => {
console.log(`Client disconnected: ${code} ${reason}`);
});
});
server.listen(9220).then(() => {
console.log('Server listening on port 9220');
});
Debug
Known issues
breakingIn version 2.0, the API was rewritten and is not backward-compatible with version 1.x. The import paths, class names, and methods changed (e.g., RPCServer instead of Server).fixUpdate code to use RPCServer, RPCClient, and new method signatures. See UPGRADING.md.
affects: >=2.0 <2.0? Actually >=2.0.0
deprecatedThe 'strictMode' option in RPCServer constructor will be removed in a future major version; use schema validation via 'ocpp-schemas' package instead.fixMigrate to external schema validation (see docs on strict validation).
affects: >=2.0.0
gotchaThe library requires Node.js >= 17.3.0 due to use of globalThis and other modern features. Older Node.js versions will throw errors.fixUpgrade Node.js to >=17.3.0 or consider using a polyfill.
affects: >=2.0.0
gotchaThe client's 'reconnect' option defaults to true; if the server closes unexpectedly, the client will keep reconnecting indefinitely. This may cause resource leaks if not configured correctly.fixSet reconnect: false if automatic reconnection is not desired, or configure maxReconnects option.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: Cannot destructure property 'RPCServer' of 'require(...)' as it is undefined.
Using CommonJS require with destructuring but importing incorrectly.
fixUse const { RPCServer } = require('ocpp-rpc'); or use ESM import. Error: subprotocol not supported
The client connected with a subprotocol not listed in the server's 'protocols' array.
fixEnsure both client and server agree on the subprotocol string (e.g., 'ocpp1.6').
TypeError: createRPCError is not a function
Using default import instead of named import.
fixUse import { createRPCError } from 'ocpp-rpc'. Audit
Dependencies
No dependency data recorded yet.