Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not provide an export named 'load' #1949

Open
Bizarrus opened this issue Nov 28, 2023 · 0 comments
Open

not provide an export named 'load' #1949

Bizarrus opened this issue Nov 28, 2023 · 0 comments

Comments

@Bizarrus
Copy link

Bizarrus commented Nov 28, 2023

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant