mapboxgl is incompatible with the CLI in a production build
See original GitHub issueBug Report or Feature Request (mark with an x
)
- [x] bug report -> please search issues before submitting
- [ ] feature request
It seems that using Mapbox GL and Angular CLI when targeting production does not work.
Running an app that imports Mapbox with import * as mapboxgl from 'mapboxgl'
via ng serve
seems to work just fine. But if you run it via:
ng serve --open --sourcemap --target=production --output-hashing=all
An error is thrown from one of the workers created by Mapbox.
Versions.
@angular/cli: 1.0.0-rc.4
node: 7.4.0
os: darwin x64
@angular/common: 2.4.10
@angular/compiler: 2.4.10
@angular/core: 2.4.10
@angular/flex-layout: 2.0.0-rc.1
@angular/forms: 2.4.10
@angular/http: 2.4.10
@angular/material: 2.0.0-beta.2
@angular/platform-browser: 2.4.10
@angular/platform-browser-dynamic: 2.4.10
@angular/router: 3.4.10
@angular/cli: 1.0.0-rc.4
@angular/compiler-cli: 2.4.10
@angular/tsc-wrapped: 0.5.2
Repro steps.
- Scaffold an Angular CLI app
- Add Mapbox GL dep
"mapbox-gl": "^0.34.0"
- Add the typings (
"@types/mapbox-gl": "^0.30.0"
) import * as mapboxgl from 'mapboxgl'
anywhere in the app (logmapboxgl
just to see the output)- Create a map in one of the components
const map: mapboxgl.Map = new Map(Object.assign({container: element}));
(element
is thenativeElement
from@ViewChild('map', {read: ElementRef}) mapRef: ElementRef
)
The log given by the failure.
blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1 Uncaught ReferenceError: e is not defined
33../support/isBuffer @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1
o @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1
(anonymous) @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1
102.util @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1
o @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1
(anonymous) @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1
128.../error/validation_error @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1
o @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1
(anonymous) @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1
142../reference/latest @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1
o @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1
(anonymous) @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1
156.../style-spec/validate_style.min @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1
o @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1
(anonymous) @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1
148.../style-spec/reference/latest @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1
o @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1
(anonymous) @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1
154.../style-spec/feature_filter @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1
o @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1
(anonymous) @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1
98.../style/style_layer_index @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1
o @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1
(anonymous) @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1
anonymous @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:3
o @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1
t @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1
(anonymous) @ blob:https://ds.infarm.com/e940fbf0-8c73-42bf-a3cd-d5326c57e0f6:1
Desired functionality.
An app using Mapbox should work when building for production.
Mention any other details that might be useful.
If I instead load Mapbox via .angular-cli.json
:
"styles": [
"../node_modules/mapbox-gl/dist/mapbox-gl.css"
],
"scripts": [
"../node_modules/mapbox-gl/dist/mapbox-gl.js"
]
It works as expected. I suspect it might have something to do with minification or some other transformation applied to one of the mapbox scripts.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:8
- Comments:54 (12 by maintainers)
Top Results From Across the Web
Issue in Ionic production build for Mapbox GL JS feature
But for production build i.e ionic cordova build android --prod ... Issue: mapboxgl is incompatible with the CLI in a production build.
Read more >Mapbox GL JS in Single-Page-Application (Vue 3) not working ...
I've created an application using Vue 3 and a map based on Mapbox GL JS (version 2.11). The app was scaffolded with Vue...
Read more >Using Mapbox GL JS with React - LogRocket Blog
Want to build map interfaces with React? In this post, learn to use react-map-gl to build two variations of map components.
Read more >mapbox-gl | Yarn - Package Manager
Mapbox GL JS is a JavaScript library for interactive, customizable vector maps on the web. It takes map styles that conform to the...
Read more >Installation | Mapbox GL JS
The JavaScript bundle is incompatible with some Babel transforms because of the way it shares code between the main thread and Web Worker....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think I have a solution to this issue…
My setup:
Install mapbox-gl (note that this is just to get the prebuilt js and css files in /dist. The source is not used) (my version is mapbox-gl@0.39.1):
npm install --save mapbox-gl
Install mapbox-gl types (my version is @types/mapbox-gl@0.39.4):
npm install --save @types/mapbox-gl
Very important - this is the key step Edit tsconfig.app.json and change the
compilerOptions/types
line:types: ["mapbox-gl", "geojson"]
Edit tsconfig.spec.json and change the
compilerOptions/types
line: types: [“mapbox-gl”, “geojson”, “jasmine”, “node”]This enables automatic inclusion of the required types from the @types packages
Add the pre-built mapbox js and css to your .angular-cli.json config:\
Now make sure that you have no
import * as mapbox from 'mapbox-gl'
statements anywhere in your codebase. You should be able to use mapbox with full typing like this e.gmapboxgl.Map
,mapboxgl.LngLat
. Geojson types are also pulled in e.g.GeoJSON.FeatureCollection<GeoJSON.GeometryObject>
Note that if you forget and leave any
import * as mapbox from 'mapbox-gl'
statements in your codebase then you will end up with 2 copies of mapboxgl - 1 from the script inclusion, and 1 built from the source. However, the 1 from the script inclusion seems to be loaded after so it will still work ok but the size of your app will be bigger.Fixed via https://github.com/angular/angular-cli/pull/7931