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

Nextjs Import Error #487

Open
Overdash opened this issue Jun 15, 2024 · 4 comments
Open

Nextjs Import Error #487

Overdash opened this issue Jun 15, 2024 · 4 comments

Comments

@Overdash
Copy link

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 <unknown> (Error: ./node_modules/keyv/src/index.js:22:14)
    at <unknown> (https://nextjs.org/docs/messages/module-not-found)

image

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?

@doktor500
Copy link

Mapbox could fix this by importing

import Keyv from "@keyvhq/core";

instead of importing

import Keyv from "keyv";

in their sdk

@Overdash
Copy link
Author

Overdash commented Jul 8, 2024

For future on-lookers: I worked around this by adding "@keyv/redis": "^2.8.5" as a dependency.

I'll leave this open to let mapbox decide if they want properly fix it or ignore it.

@whollacsek
Copy link

If you are using Next.js 15 I managed to fix this with https://rc.nextjs.org/docs/app/api-reference/next-config-js/serverExternalPackages

const nextConfig = {
  serverExternalPackages: ['@mapbox/mapbox-sdk'],
}

@Evaldas-B
Copy link

If you are using Next.js 15 I managed to fix this with https://rc.nextjs.org/docs/app/api-reference/next-config-js/serverExternalPackages

const nextConfig = {
  serverExternalPackages: ['@mapbox/mapbox-sdk'],
}

Next.js 14 has an experimental flag for this as well:

const nextConfig = {
  experimental: {
    serverComponentsExternalPackages: ["@mapbox/mapbox-sdk"],
  },
}

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

4 participants