-
-
Notifications
You must be signed in to change notification settings - Fork 590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: this.opts.request is not a function when running client in Node.js; reopen issue #1191 #2415
Comments
@jt0in3e please provide an actual snippet and error |
OS - linux (VoidLinux, 5.15.41_1) steps to reproduce:
ERROR ->
|
#2415 fixes this |
I just ran into this same error |
Node.js v17.3.0 Logs:
|
|
I just did |
@reesericci that'll be js-sdk v18.0.0 - not the changes in the PR. |
So then how do I install the fix? I'd like to continue using NPM if possible |
Either wait for the next release or install it via a github dependency https://www.pluralsight.com/guides/install-npm-packages-from-gitgithub |
What's the timeline for the next release? |
Next tuesday but the fix caused other issues downstream so has to be backed out. https://github.com/matrix-org/matrix-react-sdk/runs/6656911557?check_suite_focus=true |
I guess I'll wait for the release if the patch is causing issues. Thanks! |
Will do - thanks for the workaround! |
@t3chguy I see you reverted back changes. I've tried workarond and it works. Do I need to keep this workarond persistent? |
@jt0in3e see #2415 (comment) for why the changes were reverted |
@t3chguy ok, will stay with workaround for now, maybe smth will change in the future. Thank you for your help |
Why is this issue closed? A workaround is not a fix, this issue should stay open until a real fix is merged and validated. |
accidentally clicked on "close with comment" o_0 |
The workaround isn't working for me when I use ESM because request only supports commonjs. code:
error:
I'm using typescript with es2022 modules and es2020 target |
* Convert `getLocalAliases` to a stable API call ([\matrix-org#2402](matrix-org#2402)). * Fix request, crypto, and bs58 imports ([\matrix-org#2414](matrix-org#2414)). Fixes matrix-org#2415. * Update relations after every decryption attempt ([\matrix-org#2387](matrix-org#2387)). Fixes element-hq/element-web#22258. Contributed by @weeman1337. * Fix degraded mode for the IDBStore and test it ([\matrix-org#2400](matrix-org#2400)). Fixes matrix-org/element-web-rageshakes#13170. * Don't cancel SAS verifications if `ready` is received after `start` ([\matrix-org#2250](matrix-org#2250)). * Prevent overlapping sync accumulator persists ([\matrix-org#2392](matrix-org#2392)). Fixes vector-im/element-web#21541. * Fix behaviour of isRelation with relation m.replace for state events ([\matrix-org#2389](matrix-org#2389)). Fixes element-hq/element-web#22280. * Fixes matrix-org#2384 ([\matrix-org#2385](matrix-org#2385)). Fixes undefined/matrix-js-sdk#2384. Contributed by @schmop. * Ensure rooms are recalculated on re-invites ([\matrix-org#2374](matrix-org#2374)). Fixes element-hq/element-web#22106.
Has any fix to this issue been committed? I am getting the same error while trying to register a user. |
Is there any way to open a bounty on this issue? I'd be glad to throw some money your way if it meant that a fix would arrive. |
PR 2415 seems to not exist ? thank you, |
Getting this with a vitejs + preact + typescript setup as well when I try to login with password :/ |
It was not clear whether you're in ts or js? test.js import * as sdk from 'matrix-js-sdk'
import matrixcs from 'matrix-js-sdk'
import request from 'request'
matrixcs.request(request)
console.log('starting...')
const client = sdk.createClient('https://matrix.org')
console.log('we have a client...')
client.login('m.login.password', {
'user': '@metaspan:matrix.org',
'password': '123456'
})
.then((response) => {
console.log(response)
console.log(response.access_token)
})
.catch(err => {
console.warn('caught an error!')
console.error(err)
})
.finally(() => {
console.log('we\'re done')
})
console.debug('all done...') produces node test.js
starting...
we have a client...
all done...
{
user_id: '@metaspan:matrix.org',
access_token: 'syt_asdfasdf_asdfasdf_3b2yjA',
home_server: 'matrix.org',
device_id: 'asdfJJasdf',
well_known: { 'm.homeserver': { base_url: 'https://matrix-client.matrix.org/' } }
}
syt_asdfasdf_asdfasdf_3b2yjA
we're done |
I was using TypeScript + Rollup.js + ESM |
Is it possible there is another workaround that doesn't use the request package? I understand that work is being done to move from request to fetch but I'm just not sure how long that will take, especially since the idea of moving away from request has been around since 2018. I don't mean to be impatient or ungrateful for the work put into projects like this, I'm just hoping to find a more immediate solution to the OP problem described here without relying on requests, if it's possible. |
Given you can pass any method which fulfils the contract, you could write a |
I can't use the SDK at the moment because of this - this needs to be top priority |
Hi, I had the same issue. Setting ICreateClientOpts.request did the trick for me. ` // ... const client = sdk.createClient({ // ... |
But you're still using the requests package, which doesn't really help the rest of things out. This package has been deprecated for about 2 years already - this sdk really needs to move away from it altogether. |
Yes that's a good point. But you can also use another library as workaround as long as #801 is ongoing I think. @ghost stated an axios example there. I'm still in an dev setup and tried a little modified version just as an example if anyone is interested in. `const request = async function(opts, callback) {
}` |
any update on this issue please ? |
@andreidiaconescu there is a workaround above by passing |
Following works for me :- import * as sdk from "matrix-js-sdk";
import request from "request";
const matrixClient = sdk.createClient({
baseUrl: "https://matrix.org",
request,
});
const starting = matrixClient.startClient();
export async function notifications() {
await starting;
await matrixClient.sendMessage(<ROOM_ID>, {
body: message,
msgtype: "m.text",
});
} |
* Changes the `uploadContent` API, kills off `request` and `browser-request` in favour of `fetch`, removed callback support on a lot of the methods, adds a lot of tests. ([\matrix-org#2719](matrix-org#2719)). Fixes matrix-org#2415 and matrix-org#801. * Remove deprecated `m.room.aliases` references ([\matrix-org#2759](matrix-org#2759)). Fixes element-hq/element-web#12680. * Remove node-specific crypto bits, use Node 16's WebCrypto ([\matrix-org#2762](matrix-org#2762)). Fixes matrix-org#2760. * Export types for MatrixEvent and Room emitted events, and make event handler map types stricter ([\matrix-org#2750](matrix-org#2750)). Contributed by @stas-demydiuk. * Use even more stable calls to `/room_keys` ([\matrix-org#2746](matrix-org#2746)). * Upgrade to Olm 3.2.13 which has been repackaged to support Node 18 ([\matrix-org#2744](matrix-org#2744)). * Fix `power_level_content_override` type ([\matrix-org#2741](matrix-org#2741)). * Add custom notification handling for MSC3401 call events ([\matrix-org#2720](matrix-org#2720)). * Add support for unread thread notifications ([\matrix-org#2726](matrix-org#2726)). * Load Thread List with server-side assistance (MSC3856) ([\matrix-org#2602](matrix-org#2602)). * Use stable calls to `/room_keys` ([\matrix-org#2729](matrix-org#2729)). Fixes element-hq/element-web#22839. * Fix POST data not being passed for registerWithIdentityServer ([\matrix-org#2769](matrix-org#2769)). Fixes matrix-org/element-web-rageshakes#16206. * Fix IdentityPrefix.V2 containing spurious `/api` ([\matrix-org#2761](matrix-org#2761)). Fixes element-hq/element-web#23505. * Always send back an httpStatus property if one is known ([\matrix-org#2753](matrix-org#2753)). * Check for AbortError, not any generic connection error, to avoid tightlooping ([\matrix-org#2752](matrix-org#2752)). * Correct the dir parameter of MSC3715 ([\matrix-org#2745](matrix-org#2745)). Contributed by @dhenneke. * Fix sync init when thread unread notif is not supported ([\matrix-org#2739](matrix-org#2739)). Fixes element-hq/element-web#23435. * Use the correct sender key when checking shared secret ([\matrix-org#2730](matrix-org#2730)). Fixes element-hq/element-web#23374.
I would like to reopen the issue #1191 since there is a similar error.
I've installed
matrix-sdk-js
usingNode.js v16.15.0
and initiated client as per example. ReceivedTypeError: this.opts.request is not a function
. Also tried with nodejs v12,import
orrequire
of SDK, usingasync ... await
function, but the same issue.any ideas?
Originally posted by @jt0in3e in #1191 (comment)
The text was updated successfully, but these errors were encountered: