@google-cloud/pubsub version: 2.4.0@google-cloud/[email protected] (e.g. Message), and use itTypeError: Cannot read property 'Reader' of undefined
at ../node_modules/@google-cloud/pubsub/build/protos/protos.js:28:29
at ../node_modules/@google-cloud/pubsub/build/protos/protos.js:22:26
at Object.<anonymous> (../node_modules/@google-cloud/pubsub/build/protos/protos.js:24:3)
at Object.<anonymous> (../node_modules/@google-cloud/pubsub/src/index.ts:156:1)
Minimal reproduction:
import { Message } from '@google-cloud/pubsub';
describe('Test', () => {
it('should work', () => {
expect(Message).toBeDefined();
});
});
I had a look through the diff between 2.3.0 and 2.4.0, but couldn't see anything suspect. I did try downgrading my Typescript version to 3.8.3 to match what this library was compiled with, but the same error occurs
Looking into this, I'm unsure how this has happened
Line 22 of protos.js in my PubSub dependency is:
module.exports = factory(require("google-gax").protobufMinimal);
This is the cause of the error, since protobufMinimal is undefined
However, I can see that this is the following in this repo:
module.exports = factory(require("protobufjs/minimal"));
If I manually replace this line in my downloaded dependency then everything works fine
The compile-protos npm script makes use of the compileProtos script, which has this snippet in it which seems to be to blame (and is ironically named, in this case 😂):
function fixJsFile(js) {
// 1. fix protobufjs require: we don't want the libraries to
// depend on protobufjs, so we re-export it from google-gax
js = js.replace('require("protobufjs/minimal")', 'require("google-gax").protobufMinimal');
// 2. add Apache license to the generated .js file
js = apacheLicense + js;
return js;
}
Not sure which dependency this script comes from though, so I'm unsure how to resolve this
Same, problem. Anyone know what the last working version is?
@npomfret 2.3.0 works fine for me
@alexander-fenster any idea on this one?
Same issue for me.
Plain Javascript.
There were some protobufjs changes (and subsequently gax) that required an update to 3.8+ on TypeScript. It looked like that got pulled in even with the existing semver ranges on pubsub. :(
For what it's worth, the range is ^3.8.3 so it should be okay to use any 3.x version. (That was not true for a sort of odd breaking change in 3.7, but that is hopefully behind us at this point.)
Weirdly, the tests all passed, so... I don't know, I'll see if I can reproduce it here.
I can verify the issue. 2.3.x is good. 2.4.0 has the issue:

It looks like a fix I made last week to make synthtool happy again caused this error. I'm still looking at getting a reproduction here. A clean package with the versions @Ezard posted is actually working for me, so it's possible something needs a forced dependency version update. Can you do an npm list and let me know what the versions are for these two?
│ ├─┬ [email protected]
│ └─┬ [email protected]
In the meantime, I've reverted latest back to 2.3.0. As NawarA said, I'd recommend pulling back to that version until we can work out what's breaking in 2.4.0.
@feywind
| +-- [email protected]
| `-- [email protected]
md5-c100874b2c15648217f3dc7766e3189a
"@google-cloud/debug-agent": "5.1.2",
"@google-cloud/error-reporting": "2.0.0",
"@google-cloud/logging": "8.0.1",
"@google-cloud/pubsub": "2.4.0",
"@google-cloud/storage": "5.1.2",
"@google-cloud/trace-agent": "5.1.0",
Interestingly, I deleted my package-lock.json file and node_modules directory, reinstalled all deps, and now everything is working (and npm list shows the same versions as you see)
@Ezard Thanks for confirming that. I'm pretty sure gax 2.7.0 will fix this, and I've got a PR for that in progress.
Yup. Deleting package-lock.json and node_modules/ fixes it (in case you want a work-around)
@feywind did we ever cut a release somewhere that would fix this? A new issue popped up: https://github.com/googleapis/nodejs-logging/issues/877
Most helpful comment
Yup. Deleting
package-lock.jsonandnode_modules/fixes it (in case you want a work-around)