protobuf.js
protobuf.js copied to clipboard
not provide an export named 'load'
protobuf.js version: 7.2.5
I've tried to load the module, exactly described in the docs on following page: https://www.npmjs.com/package/protobufjs#using-the-js-api
import { load } from 'protobufjs';
file:///opt/WoRPG/Network/Protocol/Packet.js:1
import { load } from 'protobufjs';
^^^^
SyntaxError: The requested module 'protobufjs' does not provide an export named 'load'
at ModuleJob._instantiate (node:internal/modules/esm/module_job:132:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:214:5)
at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
at async loadESM (node:internal/process/esm_loader:28:7)
at async handleMainPromise (node:internal/modules/run_main:113:12)
The require-import will also not work:
const Protobuf = require('protobufjs/light');
Result:
file:///opt/WoRPG/Network/Protocol/Packet.js:1
const Protobuf = require('protobufjs/light');
^
ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/opt/WoRPG/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///opt/WoRPG/Network/Protocol/Packet.js:1:18
at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
at async loadESM (node:internal/process/esm_loader:28:7)
at async handleMainPromise (node:internal/modules/run_main:113:12)
Node.js v21.2.0
Following import will work, but has no accessible methods:
import * as Protobuf from 'protobufjs';
Protobuf.load('example.proto', function(err, root) {
// ...
});
Result:
TypeError: Protobuf.load is not a function
at new Packet (file:///opt/WoRPG/Network/Protocol/Packet.js:5:12)
at Client.onConnect (file:///opt/WoRPG/Network/Client.js:38:13)
at new Client (file:///opt/WoRPG/Network/Client.js:9:8)
at Server.<anonymous> (file:///opt/WoRPG/Network/Server.js:9:4)
at Server.emit (node:events:519:28)
at TCP.onconnection (node:net:2157:8)