Estoy tratando de averiguar por qué @here/maps-api-for-javascript no funciona en el próximo js y arroja el siguiente error:
import H from "@here/maps-api-for-javascript"; export default H; ^^^^^^ SyntaxError: Unexpected token 'export'La forma de resolver este problema es con una importación dinámica sin SSR. Si sigue la guía Uso de React proporcionada por AQUÍ, deberá importar el componente Mapa de la siguiente manera:
import dynamic from "next/dynamic"; function App() { const Map = dynamic(() => import("./Map"), { ssr: false }); return ( <div> <Map /> </div> ); } export default App; import React from 'react'; import H from "@here/maps-api-for-javascript"; export default class Map extends React.Component { constructor(props) { super(props); // the reference to the container this.ref = React.createRef(); // reference to the map this.map = null; } componentDidMount() { if (!this.map) { // instantiate a platform, default layers and a map as usual const platform = new H.service.Platform({ apikey: '{YOUR_API_KEY}' }); const layers = platform.createDefaultLayers(); const map = new H.Map( this.ref.current, layers.vector.normal.map, { pixelRatio: window.devicePixelRatio, center: {lat: 0, lng: 0}, zoom: 2, }, ); this.map = map; } } render() { return ( <div style={{ width: '300px', height:'300px' }} ref={this.ref} /> ) } }