![](/img/trans.png)
[英]Uncaught ReferenceError: require is not defined at app.js:3
[英]Mapbox gl js Uncaught ReferenceError: require is not defined
所以我在mac osx上安裝了mapbox gl js、webpack和browserify,哪些Mapbox gl js需要。 但是,當我嘗試在本地主機上運行代碼時,出現 Uncaught SyntaxError: Cannot use import statement outside a module error。
所有模塊都安裝在 Users/jbk/node-modules 目錄中,html 文件在文檔文件夾中。
<html>
<head>
<link href='https://api.mapbox.com/mapbox-gl-js/v1.8.0/mapbox-gl.css' rel='stylesheet' />
</head>
<body>
<div id='map' style='width: 400px; height: 300px;'></div>
<script>
var mapboxgl = require('mapbox-gl/dist/mapbox-gl.js');
mapboxgl.accessToken = 'pk.eyIjoic252cGxheWVyIiwiYSI6ImVmcG51V28ifQ.Dfj_Uwi6FXQu4AgmBaAESw';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v11'
});
</script>
</body>
</html>
您可以使用 mapbox 的 CDN 而不是導入 mapbox。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.