mapbox / mapbox/mapbox-sdk-js

Nextjs Import Error

Open
#487 4 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
768
Forks
191
PR merge metrics
No merged PRs in 30d

Description

I'm having trouble using the SDK in Next.js

I'm trying to (only) use the Geocoding service to retrieve Coordinates:
```
import geocodingClient from "@mapbox/mapbox-sdk/services/geocoding-v6"
```

But I get this error when Next.js tries to build my project with `@mapbox/mapbox-sdk` imported
```
Module not found
20 | if (options.adapter || options.uri) {
21 | const adapter = options.adapter || /^[^:+]*/.exec(options.uri)[0];
> 22 | return new (require(adapters[adapter]))(options);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
23 | }
24 |
25 | return new Map();

https://nextjs.org/docs/messages/module-not-found

at (Error: ./node_modules/keyv/src/index.js:22:14)
at (https://nextjs.org/docs/messages/module-not-found)
```

![image](https://github.com/mapbox/mapbox-sdk-js/assets/21345231/63109213-8ccc-40ee-9022-ac9f6ddf224c)

Seems to be coming from `keyv` in `cacheable-request` that's used by `got` package. I tried to override the package to the latest version, but no dice.

```
"overrides": {
"@mapbox/mapbox-sdk": {
"got": {
"cacheable-request": "12.0.1"
}
}
}
```

Anyone experienced this before?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the Next.js build using the geocoding-v6 import and inspect the reported dependency path through keyv/src/index.js, cacheable-request, and got. Compare the failure with the SDK's supported environments and dependency versions. Done means the import builds successfully in Next.js, or the limitation and supported usage are documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, next.js
Domain
build-system, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.