cosmos / cosmjs

The Swiss Army knife to power JavaScript based client solutions ranging from Web apps/explorers over browser extensions to server-side clients like faucets/scrapers.
https://cosmos.github.io/cosmjs/
Apache License 2.0
655 stars 344 forks source link

@cosmjs packages not compiling #1357

Open optcond opened 1 year ago

optcond commented 1 year ago

I am getting the following errors with this setup: yarn@3.3.2 node v16 and v18 typescript 4.9.3 and 4.9.4 ubuntu

Trying to build my own script with imported @cosmjs/proto-signing @cosmjs/stargate (installed via yarn add)

.yarn/cache/@cosmjs-proto-signing-npm-0.29.5-0ff97d642b-50dd19dd7d.zip/node_modules/@cosmjs/proto-signing/build/registry.d.ts:3:18 - error TS7016: Could not find a declaration file for module 'long'. '/home/meetcoin/apps/cosmjs/.yarn/cache/long-npm-4.0.0-ecd96a31ed-16afbe8f74.zip/node_modules/long/src/long.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/long` if it exists or add a new declaration (.d.ts) file containing `declare module 'long';`

3 import Long from "long";
                   ~~~~~~

.yarn/cache/@cosmjs-proto-signing-npm-0.29.5-0ff97d642b-50dd19dd7d.zip/node_modules/@cosmjs/proto-signing/build/registry.d.ts:4:27 - error TS2307: Cannot find module 'protobufjs' or its corresponding type declarations.

4 import type protobuf from "protobufjs";
                            ~~~~~~~~~~~~

.yarn/cache/@cosmjs-stargate-npm-0.29.5-47740981bc-a9859839f2.zip/node_modules/@cosmjs/stargate/build/modules/gov/queries.d.ts:4:18 - error TS7016: Could not find a declaration file for module 'long'. '/home/meetcoin/apps/cosmjs/.yarn/cache/long-npm-4.0.0-ecd96a31ed-16afbe8f74.zip/node_modules/long/src/long.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/long` if it exists or add a new declaration (.d.ts) file containing `declare module 'long';`

4 import Long from "long";

@types/long doesn't resolve the error for long; noImplicitAny silences the error, but protobufjs error still remains saying module not found. Adding with yarn doesn't fix the problem

Any advice appreciated. Thanks.

webmaster128 commented 1 year ago

Does adding "@types/long": "^4.0.1", help? Long version 5 changed to ES modules, which might create an incompatibility.

optcond commented 1 year ago

Thanks for the response! I had 2 yarn repos (clean one and my monorepo) and the clean one compiled after I put @types/long version like you've indicated. The monorepo one was still failing despite @types/long with protobuf issue. I am not sure what I did, but it started building even without specifically stating any dependencies in the package.json: I switched nvm to node v18, restarted vscode, removed all dependencies except @cosmjs and it built as is without any errors.

Thanks for your advice and your time.