parcel: Error while rendering map with mapbox-gl: "_typeof is not defined"
This a š bug report
š Configuration (.babelrc, package.json, cli command)
{
"dependencies": {
"mapbox-gl": "^0.44.1",
"parcel-bundler": "^1.7.0"
}
}
npx parcel index.html
š¤ Expected Behavior
A map should be rendered.
šÆ Current Behavior
Grey area is rendered:
The error in console:
Uncaught ReferenceError: _typeof is not defined

š Possible Solution
As far as I understood from the error and this issue from mapbox https://github.com/mapbox/mapbox-gl-js/issues/3422 it happens because parcel transpiling mapbox file that already being transpiled. Is there any way to alter that behaviour?
š» Code Sample
<html>
<head>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.44.1/mapbox-gl.css' rel='stylesheet' />
</head>
<body>
<div id='map' style='width: 400px; height: 300px;'></div>
<script src="./index.js"></script>
</body>
</html>
import mapboxgl from 'mapbox-gl'
mapboxgl.accessToken = 'pk.eyJ1IjoiZG9sYnl6ZXJyIiwiYSI6InhIS25oN0EifQ.QQrwwFUZu6trJNjGsrpTFQ'
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v9'
});
š Your Environment
Software | Version(s) |
---|---|
Parcel | 1.7.0 |
Node | v8.6.0 |
npm | 5.6.0 |
Operating System | macOS 10.13.4 |
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 30
- Comments: 23 (2 by maintainers)
Hereās my āfun with Babelā contribution.
Fiddling with my .babelrc I discovered limiting it to modern browsers worked.
After a bunch of fiddling, it seems Babelās transformation for IE and Android Browser are causing the problem. If I use the browser string ādefaults, not ie <999, not Android < 999ā to exclude those browsers, Bobās your uncle. Put either of those two browsers back in the pool,
_typeof is not defined
error.But, if I run the Mapbox GL JS library through the Babel command line (Babel CLI 6.26.0, adds 2kb to the file) and then link to it directly in the example at the top, it works fine (note no
import
is going on here).So, it looks like itās something with Babel combined with the import bundler, but only when Babel is correcting for those browsers. I guess.
May be you should try excluding /mapbox-gl from transpiling. It worked for me. My final .babelrc looks like this
Please for god sake. āJust donāt transpile the module lolā is not an answer at all. Some are actually using it in production with facing customers.
Everything about Babel here is not about fixing the issue; but avoiding the issue, making somehow Babel avoid mapbox transpilation in some context.
We need an answer. Doesnāt mapbox work in certain browser contexts because of webworkers ? Fine, please we figure it out and spell it, list it. Shouldnāt we ?
I got to fix this error using Babel 7, and
react-map-gl
What I did was install Babel 7 withyarn add -D @babel/core @babel/cli
and then add a.babelrc
file with this:According to the Babel docs, the
"loose": true
does the trick, excludingtypeof-symbol
which seems to be causing this issue.I have the same issue, still canāt find any good solution.
Excluding mapbox-gl in .babelrc did the trick for me as suggested above, but only after forcing Parcel to rebuild everything. Try --no-cache on parcel.
@cyrilchapon while I understand your frustration, this is not the right tone. This is open source software, youāre not paying a dime for Parcel and the root issue has been identified and open. Iām sure the core devs would welcome your contribution (https://github.com/parcel-bundler/parcel/issues/670) but otherwise I think you should be more respectful of all the work they have done.
Related: #670 The root cause of this issue is that we donāt support web workers. Anybody willing to contribute this feature? How would we go about doing this?
Running into this exact issue for a work project and really need a fix š
I have the same issue. but for fixing this bug, I used the Mapbox CDN instead of module bundler and finally the map area is rendered without Grey area .
<script src='https://api.mapbox.com/mapbox-gl-js/v1.12.0/mapbox-gl.js'></script>
Confirmed same issue with
react-map-gl
and even rawmapbox-gl
ā¦