Skip to content

pbjs: generate json-module target #621

@halex2005

Description

@halex2005

protobuf.js version: v6.4.1

I use

node_modules/protobufjs/bin/pbjs -p ./proto -o protoclasses-module.js -t json-module --no-delimited ./proto/**/*.proto

to generate javascript module.
Generated code has bootstrapper:

module.exports = factory(require("protobufjs/runtime"));

where the factory is

function($protobuf) {
    "use strict";
    var $root = protobuf.Root.fromJSON({

but protobufjs/runtime has no Root property exported and I get runtime error

/home/hal/git/diadocsdk-proto/protoclasses-module.js:8
        module.exports = factory(require("protobufjs/runtime"));
                         ^
TypeError: Cannot read property 'fromJSON' of undefined
    at /home/hal/git/diadocsdk-proto/protoclasses-module.js:13:30

So, I can fix this by require('protobufjs'), not require('protobufjs/runtime').
Or I can make PR with Root exported from runtime.
Which is correct usage scenario for protobuf/runtime here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions