-
-
Notifications
You must be signed in to change notification settings - Fork 756
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[typescript] import { Map } from maplibre-gl gives error 'cannot find Map' in browser #3855
Comments
How do you compile an html file as typescript? This is strange... |
I compile the mymap.ts file to mymap.min.js and have that javascript file loaded by the html page. |
I think most folks also use some sort of bundler, but it seems like this should work. I've never used an importmap though. It might be somewhat complicated by "Map" already existing though. Have you tried aliasing the import?
|
importmap is needed to be able to use a CDN, otherwise the import always looks for a local file. I've simplified the problem, because it looks like it has nothing to do with typescript. <html>
<head>
<script type="importmap">
{
"imports": {
"maplibre-gl": "https://unpkg.com/[email protected]/dist/maplibre-gl.js"
}
}
</script>
<script type="module">
import { Map } from 'maplibre-gl';
new Map({
container: 'map',
style: 'https://demotiles.maplibre.org/style.json',
center: [-74.5, 40],
zoom: 9
});
</script>
</head>
<body>
<section id="map">
</section>
</body>
</html> This should work, but doesn't as it cannot find 'Map'. An alias doesn't solve it either.
results in a module M that exists, but that module does not contain M.Map() or M.default.Map(). I think something is going wrong with exports in the maplibre-gl library. |
The following will work due to how maplibre package is built: <html>
<head>
<script type="importmap">
{
"imports": {
"maplibre-gl": "https://unpkg.com/[email protected]/dist/maplibre-gl.js"
}
}
</script>
<script type="module">
import 'maplibre-gl';
new maplibregl.Map({
container: 'map',
style: 'https://demotiles.maplibre.org/style.json',
center: [-74.5, 40],
zoom: 9
});
</script>
</head>
<body>
<section id="map">
</section>
</body>
</html> |
See also: |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Software:
I'm trying to reproduce this example in Typescript using this import example.
mymap.ts:
index.htm:
Typescript compiles, but the browser gives the error import not found: Map
I've also tried (while using
new maplibregl.Map()
instead ofnew Map()
):Is something going wrong with the exports?
The text was updated successfully, but these errors were encountered: