Protobuf.js: Cannot find name 'Long'

Created on 15 Jun 2018  路  4Comments  路  Source: protobufjs/protobuf.js

protobuf.js version: 6.8.4

After generating code using pbjs and pbjs:

node_modules/protobufjs/bin/pbjs --force-long -t static-module -w commonjs -o info.protobuf.js info.proto
node_modules/protobufjs/bin/pbts -o info.d.ts info.protobuf.js

I have included the long and @types/long in my package.json file:
"long": "^4.0.0",
"@types/long": "^4.0.0",

In my tsconfig.json file I have the following:
{ "compileOnSave": false, "compilerOptions": { ... "types": [ "node_modules/long" ], "typeRoots": [ "node_modules/@types", ] }, "include": [ "src/**/*", "src/assets/proto/*.d.ts" ], "files": [ ... ] }

I import the generated typescript file in my component but when I try to compile I get the following error in
info.d.ts: Cannot find name 'Long'

How can I resolve this issue?
Thanks in advance

bug

All 4 comments

hi did you resolve this issue eventually ? got the same issue here. thx

What worked for me was to add the following method in my app.component.ts (Angular application)

declare var require: any

export class AppComponent {
ngOnInit(){
var $protobuf = require("protobufjs/minimal");
var Long = require('long');
$protobuf.util.Long = Long;
$protobuf.configure();
}
}

Greetings! I'm pretty sure we fixed this over in #1166. We will look into cutting a release next!

Hi @JustinBeckwith, thanks for the fix! Do you know when this might make it into a release?

Was this page helpful?
0 / 5 - 0 ratings