Blank map after removing react-scripts / CRA and upgrading to Vite #2388
-
Hello, I am not sure if here is the best place or the mapbox-gl repository but figured I'd ask just in case someone had come across a similar issue. The issue is that after upgrading to Vite, React 18, and removing react-scripts, the map from mapbox no longer shows up. I get the watermark and can see the elements in the DOM but just gray blankness. There was a similar issue experienced when the project was a Create-React-App that used mapbox-gl, deck.gl, and React 16. The solution found was related to Webpack and involved importing the MapboxGLWorker and assigning it to the mapboxgl.worker class
I believe this solution is no longer applicable as the move to Vite means Webpack is no longer involved. I reached out to the Vite maintainers to see if they had any ideas on how to configure Vite to allow a similar workaround but they suggested asking around as likely someone else has experienced this issue. My best guess is this is a transpilation or esmodule issue, but my attempts at configuring Vite with Babel plugins did not seem to have any impact. There is no error message in the console or terminal to provide a clue. So it's possible that the above statement doesn't even apply for the current issue. I just recall that the symptoms were similar and scouring github issues / pr's have pointed to transpilation being related. Here is my current package.json
If anyone has experienced this or knows what may be going awry I would greatly appreciate any guidance. I can try to provide further information if that may help, but this is basically the gist of it. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Either it's a tranpilation or CSP issue, you should see an error in the console. I can't tell from your description what the cause of your problem is, or what you are trying to achieve with the workaround code. All of the examples in this repo and deck.gl use vite and React 18. |
Beta Was this translation helpful? Give feedback.
-
Sorry for the slow reply, but did find the source of the issue. Your intuition was correct in it not being a transpilation issue. In the end it was CSS reset styling declaration giving the canvas element a style of display: none 🙃 Odd part is that the styling declaration has been in there for a little over three years, so wasn't immediately apparent that that would have been the issue since I'd been working with Mapbox/react-map-gl/deck.gl for almost as long and never had an issue. The styling declaration was in the index.css file so I am thinking that Vite must be bundling the css files in a different order, where some cascading canvas declaration was previously covering up this conflict. In hindsight, makes more sense that there was no console error. I was misdiagnosing the situation from my experience with the aforementioned web worker fix. In any case, thank you very much for your willingness to help. It is only by standing on your shoulders that I am able to see |
Beta Was this translation helpful? Give feedback.
Sorry for the slow reply, but did find the source of the issue. Your intuition was correct in it not being a transpilation issue. In the end it was CSS reset styling declaration giving the canvas element a style of display: none 🙃
Odd part is that the styling declaration has been in there for a little over three years, so wasn't immediately apparent that that would have been the issue since I'd been working with Mapbox/react-map-gl/deck.gl for almost as long and never had an issue. The styling declaration was in the index.css file so I am thinking that Vite must be bundling the css files in a different order, where some cascading canvas declaration was previously covering up this conflict.
…