Repository navigation
Closed
Labels
P1Impacts a large percentage of users; if a workaround exists it is partial or overly painfulImpacts a large percentage of users; if a workaround exists it is partial or overly painfuleffort1: easy (hours)help wantedLabel noting an issue which the team is looking for contribution from the community to fixLabel noting an issue which the team is looking for contribution from the community to fixneeds: investigationRequires some digging to determine if action is neededRequires some digging to determine if action is neededtype: RFC / discussion / question
Description
Bug 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=allAn 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 (logmapboxgljust to see the output)- Create a map in one of the components
const map: mapboxgl.Map = new Map(Object.assign({container: element}));(elementis thenativeElementfrom@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.
Reacted by Andre Kosak, Brandon Reid, Guillaume de Jabrun, Robin Summerhill, Alexander Mortensen, Mehdi Saeedifar, Saulnier and Thabang Chukura
Metadata
Metadata
Assignees
Labels
P1Impacts a large percentage of users; if a workaround exists it is partial or overly painfulImpacts a large percentage of users; if a workaround exists it is partial or overly painfuleffort1: easy (hours)help wantedLabel noting an issue which the team is looking for contribution from the community to fixLabel noting an issue which the team is looking for contribution from the community to fixneeds: investigationRequires some digging to determine if action is neededRequires some digging to determine if action is neededtype: RFC / discussion / question
Activity
brandonreid commentedon Apr 26, 2017
Any word on this one? Other issues around the internets seem to point to uglifyjs causing issues. Since Angular-cli doesn't let you modify the webpack.config directly, I can't figure out a way to tell uglify not to touch mapbox.
robinsummerhill commentedon May 2, 2017
You mention a workaround where you load the pre-built mapbox-gl library from .angular-cli.json. Could you elaborate on this? I've added the entry to 'scripts' but webpack is still building mapbox from source.
rolandjitsu commentedon May 2, 2017
@robinsummerhill I don't prebuild anything, just see the last part of my post. I just manually add it to
scripts/styles. Mapbox already provides a built version in their package as it's pointed out in the paths I have in the post (node_modules/mapbox-gl/dist/mapbox-gl.css,node_modules/mapbox-gl/dist/mapbox-gl.js).rbonillajr commentedon May 3, 2017
Hi, I have the same case.
Attached link of my site: http://54.186.39.232/
Find this example. https://github.com/haoliangyu/ngx-mapboxgl-starter
Looks like a webpack problem.
Could someone help us?
Thanks.
robinsummerhill commentedon May 4, 2017
@rolandjitsu By 'pre-built' library, I meant the pre-built version Mapbox supplies in the dist directory. I added the style and script config to .angular-cli.json as you suggested:
"styles": [ "../node_modules/mapbox-gl/dist/mapbox-gl.css" ], "scripts": [ "../node_modules/mapbox-gl/dist/mapbox-gl.js" ]However, I still see the 'e is not defined' errors you describe above and I'm still guessing that the Mapbox source is being used rather than the pre-built, pre-minified version.
rolandjitsu commentedon May 4, 2017
@robinsummerhill note that you have to remove imports of mapbox as well. I have a
mapbox.ts, which expects mapbox to be available as a global object on the window, that looks like:Then I import things I need from that file.
robinsummerhill commentedon May 4, 2017
@rolandjitsu Thanks - that was the missing bit.
rbonillajr commentedon May 5, 2017
@robinsummerhill this it is my code.
yarn install
With this command runs
ng serve --open --sourcemap --target=development --output-hashing=all
With this command gives the error
ng serve --open --sourcemap --target=production --output-hashing=all
ui.zip
mmartimo commentedon May 23, 2017
+1
mmartimo commentedon May 23, 2017
I have updated the .angular-cli.json and removed the import statements I was using... but then in my project I get errors from webpack returning "Cannot find name 'mapboxgl'."
For those that got the workaround functional, did you remove "types/mapbox-gl"? Any other thoughts on what might be causing this?
44 remaining items
aptogo commentedon Nov 9, 2017
I'm still seeing the same issue too. Angular 5 and CLI 1.5.0.
khanhvuNOIS commentedon Nov 11, 2017
@vecernik could you give us your configuration? Angular 5 and CLI 1.5.0 does not resolve this issue
Wykks commentedon Nov 13, 2017
@khanhvuNOIS Can you try this PR ? #7931
SublimeProphets commentedon Nov 13, 2017
@Wykks the solution in your PR #7931 works perfect for me.
I'm running angular 5.0.1 and angular-cli 1.5.0 and declaring mapbox-gl as follow (in my index.ts -> creating a custom module)
declare const mapboxgl: any;khanhvuNOIS commentedon Nov 13, 2017
@Wykks I could confirm the PR works perfectly. Hope it will be merged soon
vecernik commentedon Nov 13, 2017
@khanhvuNOIS I'm sorry to confuse you, I meant ng5+cli1.5.0 builds well my project with Faye.
Bexanderthebex commentedon Nov 26, 2017
I'm sorry I am new to angular and mapboxgl.js, how can I set noParse to false in the webpack config? what files can I find it? Many thanks!
Wykks commentedon Nov 26, 2017
@Bexanderthebex you can eject from cli https://github.com/angular/angular-cli/wiki/stories-moving-out-of-the-cli and you will have access to the webpack config.
Or you can download this patch https://github.com/Wykks/ngx-mapbox-gl/blob/e0b18aaf74c669f26c8964f8bfb0f8617f21173a/ngcli-comparisons-false.patch
Then add this to your package.json:
"postinstall": "patch -N -p1 < ngcli-comparisons-false.patch &2>/dev/null"(for linux. Adapt this if you're on windows of course)You can also load mapbox-gl globally to avoid this error (see above). But doing this way, you can't lazy load mapbox-gl.
filipesilva commentedon Nov 29, 2017
Fixed via #7931
fix(@angular/cli): disable node global
agiratech-vigneshm commentedon Aug 20, 2018
Upgrading to mapbox-gl.js 0.48.0 fixes this error if anyone still experiences this. I got it suddenly after moving to angular 6.1
angular-automatic-lock-bot commentedon Sep 8, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.
fix(@angular/cli): disable node global