[英]Mapbox gl js Uncaught ReferenceError: require is not defined
So I installed mapbox gl js, webpack, and browserify which Mapbox gl js requires on mac osx.所以我在mac osx上安装了mapbox gl js、webpack和browserify,哪些Mapbox gl js需要。 However, I get Uncaught SyntaxError: Cannot use import statement outside a module error when I try to run the code on localhost.但是,当我尝试在本地主机上运行代码时,出现 Uncaught SyntaxError: Cannot use import statement outside a module error。
All the modules are installed in Users/jbk/node-modules directory, and html file is in document folder.所有模块都安装在 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.