You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Alpine.js中使用OpenLayers.js时遇导出错误的求助

Alpine.js集成OpenLayers.js时遇到"ambiguous indirect export: default"错误

我正尝试在Alpine.js中集成OpenLayers.js,但遇到无法解决的错误:
Uncaught SyntaxError: ambiguous indirect export: default
对应的导入语句:import olJf from "./dist/js/oljf.js";

源文件(oljf.js)

//oljf.js
import Map from 'ol/Map.js';
import OSM from 'ol/source/OSM.js';
import TileLayer from 'ol/layer/Tile.js';
import View from 'ol/View.js';

export default function olJf () {
    new Map({
        target: 'map',
        layers: [
            new TileLayer({
                source: new OSM(),
            }),
        ],
        view: new View({
            center: [0, 0],
            zoom: 2,
        }),
    })
};

编译后在Alpine组件中的导入代码

//compiled file
import olJf from "./dist/js/oljf.js";

document.addEventListener('alpine:init', () => {

    Alpine.data('map', () => ({
            latitude: false,
            longitude: false,
            isLoading: false,
            init() {
                console.log(`map for ${this.latitude}`);
                console.log(window.oljf)
                const mapdiv = document.getElementById('openmap_offre')
                olJf()
            }
        })
    )
})

调用Alpine的HTML代码

<head>
    <script type="module" src="https://xxx.be/wp-content/themes/visittail/assets/js/map.js" defer></script>
</head>
<body>
 <div id="openmap_offre" class="mt-3" style="width: 100%; height: 400px;" x-data="map" x-init="initMap">
</div>
</body>

内容的提问来源于stack exchange,提问作者Jsenechal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 16:10:33