mapbox-gl-directions: MapboxDirections was not found
@tristen @mapsam @willwhite @tmcw
I am using this package for a react app and the steps i have followed are:
npm install --save @mapbox/mapbox-gl-directions
then inside of my App.js
import MapboxDirections from "@mapbox/mapbox-gl-directions";
export default class MyMap extends Component{
componentDidMount(){
mapboxgl.accessToken = my token is placed here;
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/basic-v9',
zoom: 4,
center: [77.4126, 23.2599]
});
map.addControl(new mapboxgl.FullscreenControl());
map.addControl(new mapboxgl.GeolocateControl());
map.addControl(new MapboxGeocoder({accessToken:mapboxgl.accessToken}));
map.addControl(new mapboxgl.NavigationControl());
map.addControl(new MapboxDirections({accessToken: mapboxgl.accessToken}), 'top-left');
}
the error is as follows:
"export 'default' (imported as 'MapboxDirections') was not found in '@mapbox/mapbox-gl-
directions'
If you do something like this, even though it is a “default export”
import { MapboxDirections } from "@mapbox/mapbox-gl-directions";
the previous error gets fixed and a new error shows up about Geocoder or something else.
About this issue
- Original URL
- State: open
- Created 6 years ago
- Comments: 22 (2 by maintainers)
@sathya9897 Not sure if you figured it out. I have a work around to get it to work in react. Importing the dist folder instead of src will avoid the errors.
import Directions from '@mapbox/mapbox-gl-directions/dist/mapbox-gl-directions';Maybe it’s not the ideal solution, if not, let me know.
For all new people have problem for import do this;
work on Quasar Framework / Vue 2
For reference, if you are using react you might want to do something like this. I’ve hacked some values for simplicty (the original code uses redux).
@mariusa Please reference @itsalb3rt’s answer. The method of importing Mapbox GL Directions seems to work properly. Initially I encountered the same error you mentioned and resolved it with his proposed import method.
hay everyone, i try add this code to my project but form direction that created before not showing, this form show behind the map,
here is my code
`import { Component, ViewChild, ElementRef } from ‘@angular/core’; import { IonicPage, NavController, NavParams } from ‘ionic-angular’; import leaflet from ‘leaflet’; import mapboxgl from ‘mapbox-gl’; import ‘leaflet-search’; import MapboxGeocoder from ‘@mapbox/mapbox-gl-geocoder’;
import Directions from ‘@mapbox/mapbox-gl-directions/dist/mapbox-gl-directions’;
/**
declare var mapboxgl; declare var MapboxDirections;
@IonicPage() @Component({ selector: ‘page-map’, templateUrl: ‘map.html’, }) export class MapPage { @ViewChild(‘map’) mapContainer : ElementRef; map : any; searchControl : any; constructor(public navCtrl: NavController, public navParams: NavParams, ) {
}
ionViewDidEnter() { this.loadmap(); }
loadmap() {
}}));
}
componentDidMount(){
} `
and there is my html code `<!– Generated template for the MapPage page.
See http://ionicframework.com/docs/components/#navigation for more info on Ionic pages and navigation. –> <ion-header> <ion-navbar> <ion-title>map</ion-title> </ion-navbar> </ion-header>
<ion-content padding> </ion-content> <ion-content></ion-content>`
can u help me ?
any updates on this issue?
README’s usage instructions doesn’t work, I get same error as in #91
@itsalb3rt comment does work, thanks!
Great to hear. Thanks @davidyu37 for providing a workaround!
No one has said we aren’t fixing this. This ticket is how we learn! Looks like @lbud is thinking about it ❤️ https://github.com/mapbox/mapbox-gl-directions/issues/160