6

I just added "@google-cloud/logging-winston":"2.1.0", in my pacakge.json and when I compile I get the following errors. I have seen this with other google libraries occasionally, and its root cause is most likely deeper in the stack in automatic generated types from protobuf definitions.

../node_modules/@google-cloud/logging/build/proto/logging.d.ts:1434:32 - error TS2304: Cannot find name 'Long'.

1434                 line?: (number|Long|null);
                                    ~~~~

../node_modules/@google-cloud/logging/build/proto/logging.d.ts:1453:38 - error TS2304: Cannot find name 'Long'.

1453                 public line: (number|Long);
                                          ~~~~

../node_modules/@google-cloud/logging/build/proto/logging.d.ts:1543:39 - error TS2304: Cannot find name 'Long'.

1543                 requestSize?: (number|Long|null);
                                           ~~~~

../node_modules/@google-cloud/logging/build/proto/logging.d.ts:1549:40 - error TS2304: Cannot find name 'Long'.

1549                 responseSize?: (number|Long|null);
                                            ~~~~

../node_modules/@google-cloud/logging/build/proto/logging.d.ts:1576:42 - error TS2304: Cannot find name 'Long'.

1576                 cacheFillBytes?: (number|Long|null);

3 Answers 3

12

Here is how I worked around this issue until it is taken care of.

  1. In your package.json dependencies section add "long":"4.0.0",
  2. In your package.json devDependencies section: add "@types/long":"4.0.0",
  3. Finally, in tsconfig.json (add to tsconfig.app.js if that doesn't work) (or in the tsc command line) add:
{
   "compilerOptions": {
     ...
     "types": [
       ...
       "long"
     ],
   ...
}
Sign up to request clarification or add additional context in comments.

3 Comments

This worked. Is there an official fix or something?. Thanks!
I have no idea, from what I read I have concluded that the Google Cloud node libraries team quickly jumps to the latest typescript compiler for their modules without thinking through the implications to users who use their modules with older versions of the Typescript compiler. Hopefully, as long as you keep upgrading your Typescript compiler as well the issue will go away. And hopefully they will become more sensitive to such issues.
now this solution is not working :(
6

gae123 suggestion did not work for me on typescript version 4.9.4. I added the following to tsconfig.json. Hope this helps.

"compilerOptions":{
      ...
      "skipLibCheck": true,
}

Comments

2

I solved adding the long packet and @types/long, as gae123 suggested, but now the type is not to add in tsconfig.json but in tsconfig.app.json.

"compilerOptions": {
  ...
  "types": [...,"long"]
}

Thanks gae123!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.