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: self.client.sendRequest is not a function #439

Open
AldoCF96 opened this issue May 16, 2022 · 6 comments
Open

TypeError: self.client.sendRequest is not a function #439

AldoCF96 opened this issue May 16, 2022 · 6 comments

Comments

@AldoCF96
Copy link

This error appears went trying to make a geocode call:

TypeError: self.client.sendRequest is not a function
at MapiRequest.send (mapi-request.js:160:1)
at MapboxApi (mapbox-api.tsx:15:1)
at renderWithHooks (react-dom.development.js:16141:1)
at mountIndeterminateComponent (react-dom.development.js:20838:1)
at beginWork (react-dom.development.js:22342:1)
at beginWork$1 (react-dom.development.js:27219:1)
at performUnitOfWork (react-dom.development.js:26395:1)
at workLoopSync (react-dom.development.js:26303:1)
at renderRootSync (react-dom.development.js:26271:1)
at performSyncWorkOnRoot (react-dom.development.js:25924:1)

image

this is the code:

import mbxClient from "@mapbox/mapbox-sdk/lib/classes/mapi-client"
import mbxGeocoding from "@mapbox/mapbox-sdk/services/geocoding"

const baseClient = new mbxClient({
accessToken:
"pk.eyJ1IjoiYWlybWF0cml4NjQ3IiwiYSI6ImNqeG5wZXNlajBoMGUzbm82ZjcweWF0OHkifQ.4iv7e_Bep3UXFbhp7nUqHQ",
})
const geocodingClient = mbxGeocoding(baseClient)

export interface MapboxApiProps {}

export function MapboxApi(props: MapboxApiProps) {
geocodingClient
.forwardGeocode({
query: "Paris, France",
limit: 2,
})
.send()
.then((response) => {
const match = response.body
console.log(match)
})

return (
	<div>
		<h1>Welcome to MapboxApi!</h1>
	</div>
)

}

export default MapboxApi

@boxman0617
Copy link
Contributor

bump. Getting the same on:

Screen Shot 2022-07-25 at 9 21 28 AM

@boxman0617
Copy link
Contributor

@AldoCF96 I figured it out! Check which access token you are passing to your client.
For most of these server side requests, you will want to use the secret access token. It starts with "sk."
If the token you are using starts with "pk.", it will fail with that cryptic error

@busybox11
Copy link

@boxman0617 Hi, thanks for your answer! I feel more confident using this client with TypeScript. It has been absolutely horrible to figure out the import and type definitions because the default export wouldn't work lol.

Though I'm still having the same issue. weird thing is that with a pk token, it works fine on my already existing JS project with the exact same code copy pasted.

I wouldn't have figured out the sk token part, but it still returns the same error on my new project. Is there anything else to do?

@markhker
Copy link

@busybox11 The imported client is probably wrong, I am running this in a Remix.js project, in esm. I faced the same error, and browsing the code to see which file contains the correct method, for my case changing the first line to:
import mbxClient from '@mapbox/mapbox-sdk/lib/node/node-client.js'

did the trick, it is now working. effectively there is no sendRequest function in mapi-client but there is one in node-client

@busybox11
Copy link

Yeah that's what I did. I believe my error came from the fact that I was using bun (yeah I know. sorry)

Although the token thing didn't help. This is weird. Doing the request manually with the same token works. The library is probably doing something wrong - looks like many things are wrong with it lol

@Dakuan
Copy link

Dakuan commented Mar 17, 2024

same thing with next js,

import mbxClient from '@mapbox/mapbox-sdk/lib/node/node-client.js' fixes the code...but breaks typescript

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

No branches or pull requests

5 participants