Skip to content

Angular2+ can't load proto files #1040

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

Closed
her-m opened this issue May 4, 2018 · 1 comment
Closed

Angular2+ can't load proto files #1040

her-m opened this issue May 4, 2018 · 1 comment

Comments

@her-m
Copy link

her-m commented May 4, 2018

protobuf.js version: <6.8.6>

Hello, I'm trying to integrate Protobuf.js in my Angular 4 project. I'm following the example on the Github page and generated my .proto file. I'm stuck on trying to load my proto file which is in the same folder as my .ts file. I also tried #797 but the result is the same.

image

Here's a small snippet of what I'm trying to do.

import { Injectable } from '@angular/core';
import * as protobuf from 'protobufjs';

@Injectable()

export class ProtobufService {
    constructor() {
        protobuf.configure();
    }

    start() {
        protobuf.load('./awesome.proto', function(err, root) {
    }
}

And the result I get. I tried including the relative and absolute paths and no success.

GET http://localhost:4200/awesome.proto 404 (Not Found)
ERROR Error: status 404
    at XMLHttpRequest.fetchOnReadyStateChange [as __zone_symbol__ON_PROPERTYreadystatechange] (index.js:90)

Any idea ?

@her-m
Copy link
Author

her-m commented May 7, 2018

Okay I resolved it.
I tried a bunch of things, Angular finds the file but I had to put it in the assets folder.

  protobuf.load(('/assets/awesome.proto'), function(err, root) {
            if (err)
                throw err;
// etc

@her-m her-m closed this as completed May 7, 2018
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