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

Cannot read properties of undefined (reading 'indexOf') #1958

Open
justaguyin2k23 opened this issue Jan 9, 2024 · 0 comments
Open

Cannot read properties of undefined (reading 'indexOf') #1958

justaguyin2k23 opened this issue Jan 9, 2024 · 0 comments

Comments

@justaguyin2k23
Copy link

justaguyin2k23 commented Jan 9, 2024

protobuf.js version: 7.2.5
gprc-js version 1.9.13
proto-loader version 0.7.10

line #488 of [protobuf.js/ext/descriptor/index.js]

if ((descriptor.oneofIndex = this.parent.oneofsArray.indexOf(this.partOf)) < 0)
        throw Error("missing oneof");

causes the error Cannot read properties of undefined (reading 'indexOf') when calling proto-loader's loadSync function.

const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const pathLib = require('path');
const proto_path = [
  pathLib.join(__dirname,'./protos/dummy_service.proto')
];
 const packageDefinition = protoLoader.loadSync(protopath);

This specifically happens when the latest version of buf/validate.proto is among the proto files being used.

Changing line #488 to below solves the issue,

if ((this.parent.oneofsArray && descriptor.oneofIndex = this.parent.oneofsArray.indexOf(this.partOf)) < 0)

Stacktrace

From Node.js Internals:
  TypeError: Cannot read properties of undefined (reading 'indexOf')
      at Field.toDescriptor (/Users/tiredcoder/dev/cypress-tests/node_modules/protobufjs/ext/descriptor/index.js:488:62)
      at Root_toDescriptorRecursive (/Users/tiredcoder/dev/cypress-tests/node_modules/protobufjs/ext/descriptor/index.js:142:40)
      at Root_toDescriptorRecursive (/Users/tiredcoder/dev/cypress-tests/node_modules/protobufjs/ext/descriptor/index.js:146:13)
      at Root_toDescriptorRecursive (/Users/tiredcoder/dev/cypress-tests/node_modules/protobufjs/ext/descriptor/index.js:146:13)
      at Root.toDescriptor (/Users/tiredcoder/dev/cypress-tests/node_modules/protobufjs/ext/descriptor/index.js:121:5)
      at createPackageDefinition (/Users/tiredcoder/dev/cypress-tests/node_modules/@grpc/proto-loader/src/index.ts:327:66)
      at Object.loadSync (/Users/tiredcoder/dev/cypress-tests/node_modules/@grpc/proto-loader/src/index.ts:392:10)
 
     at createService (/Users/tiredcoder/dev/cypress-tests/cypress.config.ts:38:49)

I see a somewhat similar issue, #1898 but no resolution.

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