Skip to content
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 #1191

Closed
matt-bro opened this issue Jan 31, 2020 · 10 comments · Fixed by #1207
Closed

TypeError: this.opts.request is not a function #1191

matt-bro opened this issue Jan 31, 2020 · 10 comments · Fixed by #1207

Comments

@matt-bro
Copy link

Hi guys,

I followed the instructions on the matrix site, on how to implement the client with node js.
I am using the matrix js sdk 4.0.0 and node js 12.10.0
After I run the node js application I receive an error "this.opts.request is not a function".
The same code is working for me in an electron app.

Here is the source code and the error message below:

const sdk = require('matrix-js-sdk') ;
const myUserId = "userid";
const myAccessToken = "accesstoken";  
const client = sdk.createClient({  
    baseUrl: "url",  
    accessToken: myAccessToken,  
    userId: myUserId  
 })  
 client.startClient();  
 client.once('sync', function(state, prevState, res) {  
    console.log(state); // state will be 'PREPARED' when the client is ready to use  
});   
/Users/matt/.nvm/versions/node/v12.10.0/bin/node --inspect-brk=5072 index.js
Debugger listening on ws://127.0.0.1:5072/603a1fcb-cd96-4268-a8c1-d45351dfc03d
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Getting saved sync token...
Getting push rules...
Got saved sync token
Getting saved sync...
null: Getting push rules failed
null: TypeError: this.opts.request is not a function
message: "this.opts.request is not a function"
stack: "TypeError: this.opts.request is not a function
    at MatrixHttpApi._request (/Users/matt/Projects/Other/strapi/my-first-matrix-client/node_modules/matrix-js-sdk/lib/http-api.js:711:23)
    at MatrixHttpApi.requestOtherUrl (/Users/matt/Projects/Other/strapi/my-first-matrix-client/node_modules/matrix-js-sdk/lib/http-api.js:587:17)
    at MatrixHttpApi.request (/Users/matt/Projects/Other/strapi/my-first-matrix-client/node_modules/matrix-js-sdk/lib/http-api.js:545:17)
    at MatrixHttpApi.authedRequest (/Users/matt/Projects/Other/strapi/my-first-matrix-client/node_modules/matrix-js-sdk/lib/http-api.js:497:33)
    at MatrixClient.MatrixBaseApis.getPushRules (/Users/matt/Projects/Other/strapi/my-first-matrix-client/node_modules/matrix-js-sdk/lib/base-apis.js:1633:21)
    at getPushRules (/Users/matt/Projects/Other/strapi/my-first-matrix-client/node_modules/matrix-js-sdk/lib/sync.js:506:35)
    at SyncApi.sync (/Users/matt/Projects/Other/strapi/my-first-matrix-client/node_modules/matrix-js-sdk/lib/sync.js:666:5)
    at MatrixClient.startClient (/Users/matt/Projects/Other/strapi/my-first-matrix-client/node_modules/matrix-js-sdk/lib/client.js:4682:17)
    at Object.<anonymous> (/Users/matt/Projects/Other/strapi/my-first-matrix-client/index.js:11:9)
    at Module._compile (internal/modules/cjs/loader.js:933:14)"
__proto__: Error {constructor: , name: "TypeError", message: "", …}
Waiting for saved sync before retrying push rules...
Got reply from saved sync, exists? false
ERROR

Did someone have a similar problem with a node only implementation?

@SebastianRiga
Copy link

I recieve the same error when calling client.startClient({initialSyncLimit: 10}), also from the examples.

@gavtaylor
Copy link

Ive been having this issue as well trying to get hubot connecting to matrix, I had to drop back to v2.4.6 before it started working.

@freelock
Copy link

freelock commented Feb 8, 2020

Same issue here -- upgrading my bot to matrix-js-sdk@4 fails with this error, works fine at @2 (but not @3.

@uhoreg
Copy link
Member

uhoreg commented Feb 11, 2020

I think this is caused by https://github.com/matrix-org/matrix-js-sdk/blob/develop/src/index.ts#L20 . As I understand it, using import in this way returns a promise, rather than the actual module. So I think we either need to do matrixcs.request(await import("request"));, or else import * as request from "request"; matrixcs.request(request);

@t3chguy
Copy link
Member

t3chguy commented Feb 11, 2020

await import there wouldn't work in an env without top-level async-await, the latter sounds sane though

@jt0in3e
Copy link

jt0in3e commented May 30, 2022

I would like to reopen the issue since there is a similar error.
I've installed matrix-sdk-js using Node.js v16.15.0 and initiated client as per example. Received TypeError: this.opts.request is not a function. Also tried with nodejs v12, import or require of SDK, using async ... await function, but the same issue.
any ideas?

@matt-bro
Copy link
Author

Did you try to downgrade the matrix js sdk version, to see if this improves the problem? It really helped us in the past to downgrade and compare a working old version of the sdk with a newer one.

@t3chguy t3chguy reopened this May 31, 2022
@t3chguy t3chguy closed this as completed May 31, 2022
@dcolley
Copy link

dcolley commented Jul 19, 2022

Downgrading the matrix sdk version is not a solution... discussion continues here #2415

@safalbk
Copy link

safalbk commented Jul 29, 2022

any solution?? plz

@t3chguy
Copy link
Member

t3chguy commented Jul 29, 2022

@safalbk see #2415 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants