title: How to load a proto file with imports
body: <p>I am using the <a href="https://github.com/dcodeIO/protobuf.js" rel="nofollow noreferrer">dcodeIO/protobuf.js</a> lib (version 6.8.4) to parse protobuf messages in the browser.
  I can make it work with simple proto files, as long as another proto file is not imported.</p>
  
  <p>Importing other proto files in the main one breaks everything.</p>
  
  <p>This is what I have:</p>
  
  <ul>
  <li><p>File struct</p>
  
  <pre><code>- assets/
      |-api/
      |    |-v1/
      |    |    |-messageB.proto
      |    |-messageA.proto
  - foo.js
  </code></pre></li>
  <li><p>messageA.proto</p>
  
  <pre><code>syntax = "proto3";
  package com.assets.api;
  import "api/v1/messageB.proto";
  
  message MessageA{
      MessageB foo = 0;
  }
  </code></pre></li>
  <li><p>messageB.proto</p>
  
  <pre><code>syntax = "proto3";
  package com.assets.api.v1;
  
  message MessageB {
      string bar= 0;
  }
  </code></pre></li>
  <li><p>with 6.8.4:</p>
  
  <pre><code>var MessageProto = null;
  protobuf.load({root:"assets", file:"api/messageA.proto"}, function (err, root) {
      if (root) { MessageAProto = root.lookupType("com.assets.api.MessageA");
  }});
  data = MessageProto .decode(rawData);
  </code></pre></li>
  </ul>
  
  <p>.</p>
  
  <pre><code>    Error: no such type
  
  at Root.lookupType (http://localhost:63342/xx/build/app/vendor/protobuf/dist/protobuf.js:3463:15)
  at http://localhost:63342/xx/build/app/src/app/asset/asset.module.js:320:53
  at finish (http://localhost:63342/xx/build/app/vendor/protobuf/dist/protobuf.js:5212:9)
  at Root.load (http://localhost:63342/xx/build/app/vendor/protobuf/dist/protobuf.js:5316:9)
  at Object.load (http://localhost:63342/xx/build/app/vendor/protobuf/dist/protobuf.js:2547:17)
  at new &lt;anonymous&gt; (http://localhost:63342/xx/build/app/src/app/asset/asset.module.js:316:22)
  at Object.instantiate (http://localhost:63342/xx/build/app/vendor/angular/angular.js:4786:14)
  at $controller (http://localhost:63342/xx/build/app/vendor/angular/angular.js:10607:28)
  at Object.&lt;anonymous&gt; (http://localhost:63342/xx/build/app/vendor/angular-ui-router/release/angular-ui-router.js:4081:28)
  at http://localhost:63342/xx/build/app/vendor/angular/angular.js:1259:18
  </code></pre>
  
  <ul>
  <li><p>with 5.0:</p>
  
  <pre><code>var MessageProto = null;
  dcodeIO.ProtoBuf.convertFieldsToCamelCase = true;
  dcodeIO.ProtoBuf.loadProtoFile({root: "assets", file: "api/messageA.proto"}, function (err, builder) {
      if (builder) { MessageProto = builder.build("com.assets.api.MessageA");
   }});
  data = MessageProto .decode(rawData);
  </code></pre>
  
  <p>. </p>
  
  <pre><code>OK
  </code></pre></li>
  </ul>