-
Notifications
You must be signed in to change notification settings - Fork 12k
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
mapboxgl is incompatible with the CLI in a production build #5804
Comments
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. |
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. |
@robinsummerhill I don't prebuild anything, just see the last part of my post. I just manually add it to |
Hi, I have the same case. |
@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:
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. |
@robinsummerhill note that you have to remove imports of mapbox as well. I have a // TODO: Eventually use the import, but as of right now (03.04.2017), Mapbox and Angular CLI do not work if we import Mapbox
// TODO: Tracked issue at https://github.com/angular/angular-cli/issues/5804
// import * as mapboxgl from 'mapbox-gl';
import {mapboxAccessToken} from '../../../env';
Object.assign(mapboxgl, {
accessToken: mapboxAccessToken
});
const {Map, AttributionControl, LngLat, LngLatBounds} = mapboxgl;
export {
Map,
AttributionControl,
LngLat,
LngLatBounds
}; Then I import things I need from that file. |
@rolandjitsu Thanks - that was the missing bit. |
@robinsummerhill this it is my code. yarn install With this command runs With this command gives the error |
+1 |
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? |
@mmartimo you need to let TypeScript know about the mapboxgl global variable. Add the following to your typings.d.ts file:
|
@aptogo thanks so much for jumping in... I'm really sorry, but I'm still missing something.
But now, it is upset a few lines down when I declare map: Map; Webpack now gives: Conveniently my IDE gives the same: I also tried reinstalling the types/mapbox-gl module... seems there is no effect positive or negative. Please let me know if any other ideas? |
Seems to work now 🎉 But more people should confirm it. |
@rolandjitsu what configuration did you use? |
@rbonillajr what do you mean? The angular CLI config? There's nothing in the config related to mapbox. You just need to make sure you add the typings for it via |
@rolandjitsu in production target is broken. in dev work package.json
tsconfig
ng Service
ng component
html component
|
@rbonillajr try to format your code a bit better and please add the error message. |
@rolandjitsu sorry. I fixed it. |
@rbonillajr did you try to update zone.js and @angular to the latest versions, I know that zone.js is at around And I'd move: Object.assign(mapboxgl, {
accessToken: mapboxAccessToken
}); To the root of the file, outside of the constructor. No point to have that in the constructor since you only need to do it once and your service might be instantiated more than once if you import it in different modules. Also, you might want to do the following when creating the map (mind the incomplete example): class MapComponent {
@ViewChild('mapa', {read: ElementRef}) mapRef: ElementRef;
ngOnInit() {
this.map = new Map({container: this.mapRef.nativeElement ...})
}
} Also note that you might want to wait for map ready to start adding anything to it. <div #mapa></div> But you haven't provided an error message, so it's hard to tell what's going on. |
@rolandjitsu it is error message: I upgrade packages. |
@rbonillajr I've actually just noticed that I haven't test with prod target because my CI build failed and never deployed. I'll test and let you know if this error persists. |
@rbonillajr ok, so the issue still persists. I just wonder if we can skip mangling now for specific scripts. |
Fix an issue where mapbox-gl is not bundled correctly in the production build. Temporary workaround for angular/angular-cli#5804
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 [email protected]): Install mapbox-gl types (my version is @types/[email protected]): Very important - this is the key step Edit tsconfig.spec.json and change the 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 Note that if you forget and leave any |
I'm actually still seeing the same issue with the error from Mapbox. My CLI is:
Has this not been released yet? |
@filipesilva Ok, tested with latest RC version and it seems to work, but
And the error occurs at the first line: // Expose `IntlPolyfill` as global to add locale data into runtime later on.
global.IntlPolyfill = require('./lib/core.js');
// Require all locale data for `Intl`. This module will be
// ignored when bundling for the browser with Browserify/Webpack.
require('./locale-data/complete.js');
// hack to export the polyfill as global Intl if needed
if (!global.Intl) {
global.Intl = global.IntlPolyfill;
global.IntlPolyfill.__applyLocaleSensitivePrototypes();
}
// providing an idiomatic api for the nodejs version of this module
module.exports = global.IntlPolyfill;
//////////////////
// WEBPACK FOOTER
// /Users/rolandjitsu/Projects/infarm/dashboard/node_modules/intl/index.js
// module id = ../../../../intl/index.js
// module chunks = polyfills |
Then, for the 1.x release we can probably include this fix instead ? #7931 |
Is configurable 'global' is scheduled for version 1.5.0? |
Is this issue solved in version 1.5? |
Also needing a fix for this issue. |
Followed the workarounds listed above, got things working.
|
it works with angular 5 and current (1.5.0) like a charm. thank you guys. |
I am still having this issue with angular 5 and current (1.5.0). |
I'm still seeing the same issue too. Angular 5 and CLI 1.5.0. |
@vecernik could you give us your configuration? Angular 5 and CLI 1.5.0 does not resolve this issue |
@khanhvuNOIS Can you try this PR ? #7931 |
@Wykks I could confirm the PR works perfectly. Hope it will be merged soon |
@khanhvuNOIS I'm sorry to confuse you, I meant ng5+cli1.5.0 builds well my project with Faye. |
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! |
@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. |
Fixed via #7931 |
The node only `global` object had been left in because it used to cause a build size regression with Angular. This doesn't seem to be the case anymore so it should be removed because it causes problematic interactions with some libraries. Fix angular#5804 Supersedes angular#7931
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 |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug Report or Feature Request (mark with an
x
)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'
viang serve
seems to work just fine. But if you run it via:An error is thrown from one of the workers created by Mapbox.
Versions.
Repro steps.
"mapbox-gl": "^0.34.0"
"@types/mapbox-gl": "^0.30.0"
)import * as mapboxgl from 'mapboxgl'
anywhere in the app (logmapboxgl
just to see the output)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.
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
: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.
The text was updated successfully, but these errors were encountered: