near / near-api-js

JavaScript library to interact with NEAR Protocol via RPC API
https://near.github.io/near-api-js
MIT License
390 stars 244 forks source link

yarn + latest wallet selector + latest near-api-js == error #1366

Open gagdiez opened 1 month ago

gagdiez commented 1 month ago

Prerequisites

Description

Multiple people is reporting that some of our examples have stopped working when using the latest version of near-api-js and wallet-selector.

Reproducible demo

https://github.com/near-examples/guest-book-examples/tree/main/frontend

Steps to reproduce

  1. Fork the repo
  2. use yarn install on the frontend
  3. use yarn dev
  4. try to post a message without attaching NEAR

Expected behavior

A transaction saving the message should be triggered, and thus the message saved

Actual behavior

Unhandled Runtime Error

Error: Expected string not undefined(undefined) at value.signerId
Call Stack
expect_type
node_modules/borsh/lib/cjs/utils.js (34:1)
BorshSerializer.prototype.encode_string
node_modules/borsh/lib/cjs/serialize.js (85:1)
BorshSerializer.prototype.encode_value
node_modules/borsh/lib/cjs/serialize.js (45:1)
BorshSerializer.prototype.encode_struct
node_modules/borsh/lib/cjs/serialize.js (180:1)
BorshSerializer.prototype.encode_value
node_modules/borsh/lib/cjs/serialize.js (61:1)
BorshSerializer.prototype.encode
node_modules/borsh/lib/cjs/serialize.js (37:1)
serialize
node_modules/borsh/lib/cjs/index.js (35:1)
encodeTransaction
node_modules/@near-js/providers/node_modules/@near-js/transactions/lib/schema.js (35:1)
sendTransactionUntil/<
node_modules/@near-js/providers/lib/json-rpc-provider.js (81:1)
__awaiter</<
node_modules/@near-js/providers/lib/json-rpc-provider.js (8:1)
__awaiter<
node_modules/@near-js/providers/lib/json-rpc-provider.js (4:1)
sendTransactionUntil
node_modules/@near-js/providers/lib/json-rpc-provider.js (80:1)
sendTransaction/<
node_modules/@near-js/providers/lib/json-rpc-provider.js (93:1)
__awaiter</<
node_modules/@near-js/providers/lib/json-rpc-provider.js (8:1)
__awaiter<
node_modules/@near-js/providers/lib/json-rpc-provider.js (4:1)
sendTransaction
node_modules/@near-js/providers/lib/json-rpc-provider.js (92:1)
signAndSendTransaction/</result</<
node_modules/@near-js/wallet-account/node_modules/@near-js/accounts/lib/account.js (89:1)
fulfilled
node_modules/@near-js/wallet-account/node_modules/@near-js/accounts/lib/account.js (5:43)

Your environment

Self-service

jaswinder6991 commented 1 month ago

Just to add onto this, the issue is seen only while using yarn, I have not seen it when using npm or pnpm. Maybe that's a good place to start looking into it.

kujtimprenku commented 1 month ago

A potential fix https://t.me/neardev/53025 , the idea is to remove NAJ yarn remove near-api-js and then install it again yarn add near-api-js@4.0.3 in wallet-selector project.

Somehow yarn.lock there contains some wrong versions of dependencies this should fix them.

Node v22.5.1 Yarn v1.22.19

pivanov commented 1 month ago

Hey guys, the issue is related to here-wallet because @here-wallet/core@1.6.6 use near-api-js@3.0.4. I will try to find a solution asap. Thanks for provided info ... helped me a lot.

pivanov commented 1 month ago

few more:

pivanov commented 1 month ago

#1154 fix @peersyst/near-mobile-signer 🚀

pivanov commented 1 month ago

If you are using @near-wallet-selector/here-wallet, the workaround could be to specifically set these resolutions or overrides to ensure compatibility with near-api-js@^4.0.0.

This approach forces the usage of the newer version of near-api-js throughout your project.

However, please note that this is a temporary workaround and not an ideal long-term solution.

For npm, you can use overrides in your package.json like this:

"overrides": {
  "near-api-js": "^4.0.0"
}

For Yarn, you can use resolutions in your package.json like this:

"resolutions": {
  "near-api-js": "^4.0.0"
}

Hope this help.