-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Avoid errors when requiring the browser bundle in Node #9749
Conversation
You are my hero! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can confirm that this fixes the simple case of importing GL JS into a Node project as well as a Next.js test app I made (I don't appear to even need to do the dynamic
import anymore).
Sorry for the ignorance, but how do I access these changes? Are they in mapbox-gl v1.10.1 or 1.11.0-beta.1(I still get the self is not defined error)? I tried |
@MarkyMOD it will be a part of either v1.11.0-beta.2 or v1.11.0 final next week. |
@MarkyMOD you should be able to use the
This installs Rollup and builds the |
Thanks much @ryanhamley. Downloaded the source code, as the npm method didn't provide the rollup folder or rollup config, then had to transfer some dist/ files from v1.10.1 as react-mapbox-gl was looking for the .css file (dist/ only had mapbox-gl.js in there), during my Next build, which led to more errors. Anyways, is a great starting point/something to go off of, really appreciate it. Would just wait for the next release, but the client is anxious to review the map, so it goes. |
@MarkyMOD |
@ryanhamley Tried that too, but received an error of "unexpected token of '.' " without a position number, within the created css file (same error as when taking the css file from v1.10.1). Am keeping the client updated, and just going to wait for the new release, all good. |
So, webpack now gets past "self is not defined", but fails at mapbox-gl.css, when it is required by react-mapbox-gl. Am receiving the same error as my previous post: "unexpected token of '.' " I converted the file from a single line of CSS to something more readable, and it is failing at ".mapboxgl-map" (line 1), which seems to say that mapbox is not being recognized as a class/in CSS (even though the error type shows as "SyntaxError")? Is anyone else experiencing this, or have any idea of how to fix? I'm in Next.js, and using react-mapbox-gl as a middle-layer. |
It all works in Meteor after release 1.11.0 |
Hi, ReferenceError: window is not defined |
@wratte It looks like the error is coming from the Geocoder plugin, not GL JS. Can you confirm that and open an issue in that repo? https://github.com/mapbox/mapbox-gl-geocoder Alternatively, if you're trying to use geocoding functionality in Node (as opposed to rendering a map with a geocoder control), you can use our Geocoding API. |
I confirm that this is from mapbox-gl-geocoder that is using "suggestions" library which eagerly use window. I oppened an issue case: |
* Cherry pick (mapbox/mapbox-gl-js#9757) to release-erie * Cherry pick (mapbox/mapbox-gl-js#9753) to release-erie * Cherry pick (mapbox/mapbox-gl-js#9749) to release-erie * Cherry pick (mapbox/mapbox-gl-js#9748) to release-erie
Potentially fixes #4593 by adding a shim for the window object when it's not defined and a few guards when accessing it at bundle evaluation.
Launch Checklist
mapbox-gl-js
changelog:<changelog>Fix reference error when requiring the browser bundle in Node</changelog>