Skip to content
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

Missing Mapbox GL JS CSS #5785

Closed
tetsuo opened this issue Dec 1, 2017 · 14 comments
Closed

Missing Mapbox GL JS CSS #5785

tetsuo opened this issue Dec 1, 2017 · 14 comments

Comments

@tetsuo
Copy link

tetsuo commented Dec 1, 2017

I am trying to make this work with choojs and Browserify.

The error I'm getting: Missing Mapbox GL JS CSS Actually I need to open Chrome devtools to see the error message, it is written in a tag with display: none: <div class="mapboxgl-missing-css">Missing Mapbox GL JS CSS</div>

I have included a link to the CSS file in HTML, but still all I'm seeing is this error message.

What is Mapbox GL JS CSS? Is that a file name?

How do you determine that the CSS file is missing by the way? and why is that so important?

@mourner
Copy link
Member

mourner commented Dec 1, 2017

It's not an error, it's just a placeholder that becomes visible only when CSS is actually missing. Are you experiencing any problems with the map itself?

@tetsuo
Copy link
Author

tetsuo commented Dec 1, 2017

@mourner Thanks for the reply!

Following is the example I'm trying to make work:

const cache = require('cache-element')
const html = require('choo/html')
const choo = require('choo')

mapboxgl.accessToken = 'xxx';

const app = choo()
app.route('/', mainView)
app.mount('body')

const nav = cache(() => html`<div id="map" />`)

function mainView() {
  return html`
    <body onload=${() => {
      const map = new mapboxgl.Map({
        container: 'map',
        style: 'mapbox://styles/mapbox/dark-v9',
        center: [-93.261, 44.971]
      });
    }}>
      ${nav.render()}
    </body>
  `
}

and the HTML:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf8" />
    <title></title>
    <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
    <script src='https://api.mapbox.com/mapbox-gl-js/v0.42.0/mapbox-gl.js'></script>
    <link href='https://api.mapbox.com/mapbox-gl-js/v0.42.0/mapbox-gl.css' rel='stylesheet' />
  </head>
  <body>
    <script src="bundle.js"></script>
  </body>
</html>

I'm browserifying this with sheetify btw:

yarn run watchify app.js -t sheetify -o public/bundle.js -dv  

And this is the end result I'm getting:

x

@tetsuo
Copy link
Author

tetsuo commented Dec 1, 2017

It's not an error, it's just a placeholder that becomes visible only when CSS is actually missing.

So the CSS file is not missing, the placeholder message is not visible, and the map is not showing :)

@mourner
Copy link
Member

mourner commented Dec 1, 2017

Can you set up a minimal JSFiddle test case with all the already generated code? We can't afford debugging all possible configurations of front-end bundling, but with an isolated test case, it would be easy to see where the problem is.

@tetsuo
Copy link
Author

tetsuo commented Dec 1, 2017

Hmm, I'm not sure if browserify works on JSfiddle, so I can't create a proper isolated test-case on it.

I thought maybe it is a known issue, since the example I used is super easy and the browserify usage is very common. Thanks for the answer. Unfortunately I cannot afford writing a test-case right now as well :\ Good luck.

@zavan
Copy link

zavan commented Dec 15, 2017

I have the same problem, the CSS is loaded. I think it has something to do with me using React or Webpack.

@rhwilburn
Copy link

rhwilburn commented Dec 31, 2017

For me the issue was that I had the css being loaded at the bottom of the DOM, not in the Head section. It was thus flashing up on my map while it loaded the DOM.

@ryanhamley
Copy link
Contributor

I experienced this issue when upgrading from 0.40.1 to 0.43.0. Nothing else changed in my code. When downgrading back to 0.40.1, the missing CSS message went away.

@mistercrunch
Copy link

I fixed this issue by adding this line import 'mapbox-gl/dist/mapbox-gl.css';. This approach requires css-loader in babel or something like it.

@abevoelker
Copy link

No need for a JSFiddle as it's happening on the official example pages: https://www.mapbox.com/mapbox-gl-js/example/simple-map/

screenshot from 2018-02-01 13-28-02

@jfirebaugh
Copy link
Contributor

@abevoelker The presence of that div in the source shown in the developer console is expected behavior and does not indicate a problem. The Mapbox GL CSS file contains a directive that hides that div. If you are seeing it in the rendered result, it means that you forgot to include the CSS file.

@abevoelker
Copy link

abevoelker commented Feb 13, 2018 via email

@alexmac131
Copy link

For Angular 5, import the type into your style.css,

@import '../node_modules/mapbox-gl/dist/mapbox-gl.css';

Takes care of the problem completely. @mistercrunch - Thank you, for your solution, my own is just a modification of yours for Angular 5 ..

@barrylachapelle
Copy link

create-reat-app: import 'mapbox-gl/src/css/mapbox-gl.css';

toolness added a commit to JustFixNYC/who-owns-what that referenced this issue Aug 10, 2020
Fixes #191. When loading the address page, the following annoying warning is always logged:

> This page appears to be missing CSS declarations for Mapbox GL JS, which may cause the map to display incorrectly. Please ensure your page includes mapbox-gl.css, as described in https://www.mapbox.com/mapbox-gl-js/api/.

The actual page doesn't seem to have any visual problems, though... Still, the warning is annoying and according to mapbox/mapbox-gl-js#5785 we need to import the CSS in our code, which this commit does, and the warning goes away.  I just hope it's not adding unnecessary bloat to our page weight.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants