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

protobufjs latest with Angular 2 Buffer and Long not found Issue #797

Closed
progamr opened this issue May 17, 2017 · 1 comment
Closed

protobufjs latest with Angular 2 Buffer and Long not found Issue #797

progamr opened this issue May 17, 2017 · 1 comment

Comments

@progamr
Copy link

progamr commented May 17, 2017

protobuf.js version: <6.7.3>

after installing protobufjs npm install protobufjs --save in an angular 2 app i imported "load" from protobuf lib then used it
to load a .proto file the file is in the same folder of the .ts file at first compile for the app with webpack it stops and give me this error :

<ERROR in /ng2-protopuf/node_modules/protobufjs/index.d.ts (1273,46): Cannot find name 'Buffer'.

ERROR in /ng2-protopuf/node_modules/protobufjs/index.d.ts (1300,21): Cannot find name 'Long'.

ERROR in /ng2-protopuf/node_modules/protobufjs/index.d.ts (1308,22): Cannot find name 'Long'.
>

then when i comment the code for protobuf then compile it works and then uncomment and recompile it works with the protobufjs code but the .proto file can't be loaded it gave me a 404 not found error

import { Component, OnInit } from '@angular/core';
import { load } from 'protobufjs';

@Component({
  selector: 'app-list-robots',
  templateUrl: './list-robots.component.html',
  styleUrls: ['./list-robots.component.css']
})
export class ListRobotsComponent implements OnInit {

  constructor() { }

  ngOnInit() {
      // const root = parse('', { keepCase: true }).root; // or use Root#load

       load('robot.proto', function(err, root) {
          try {
          if (err) {
              throw err;
          }
          console.log('yaaaaay');
          const message = root.lookupType('RobotMessage');
          message.create({id: 1, name: 'amr'});
          console.log(`message = ${JSON.stringify(message)}`);

          const buffer = message.encode(message).finish();
          console.log(`buffer = ${Array.prototype.toString.call(buffer)}`);

          const decoded = message.decode(buffer);
          console.log(`decoded = ${JSON.stringify(decoded)}`);
          } catch (e) {
            console.log('err');
          }
      });
  }

}
@progamr progamr changed the title protobuf latest with Angular 2 Not working protobufjs latest with Angular 2 Not working May 17, 2017
@progamr
Copy link
Author

progamr commented May 20, 2017

@dcodeIO i found the solution for this issue on a previous issue here
#718
the problem was that i'm new to angular and protobufjs But any way Alhamdullah it was solved by adding these to lines to top of src/main.ts

/// <reference path="./../node_modules/protobufjs/stub-long.d.ts" />
/// <reference path="./../node_modules/protobufjs/stub-node.d.ts" />

@progamr progamr closed this as completed May 20, 2017
@progamr progamr changed the title protobufjs latest with Angular 2 Not working protobufjs latest with Angular 2 Buffer and Long not found Issue May 20, 2017
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