How to configure babel presets (and/or exclude files from transpilation) -- Mapbox GL, ReactMapGL - Blank Map #284
Unanswered
JamesRexMiller4
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Hi, Do you have any particular browser support requirement? This is the default support in Vite: https://vitejs.dev/guide/build.html#browser-compatibility For most modern project you don't need to configure anything related to transpilation. If the lib doens't work with Vite, you should instead look at the lib setup, not the transpilation setup. Try to start from on a fresh tempalate on vite.new/react-ts and add reproduce the blank map issue. You can look into the GH issues of the lib too, you're probably not the first one to use it with Vite. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
Apologies in advance for not having a reproducible example. I tried creating a codesandbox but not sure that it was actually running vite.
My issue I am experiencing is converting a create-react-app project to use vite, and in the process one of my other dependencies, mapbox-gl-js has become broken. The issue is not necessarily vite specific, but is documented here - mapbox/mapbox-gl-js#10565
And solutions for the issue are mentioned directly in the documentation - https://docs.mapbox.com/mapbox-gl-js/guides/install/#transpiling
Previously, my solution in create-react-app land was to reassign the WebWorker to a non-transpiled version. But this seems to be an option only available to WebPack from what I can see. I then tried to go down the route of adding the @babel/preset-env and browserlist per the Mapbox documentation. But I must not have been configuring it properly because as soon as I tried to do that then the whole application ceased to render and an error of "require" is not defined appeared on line 1 of my index.js despite not having a require syntax there (instead was import React from "react").
Fairly confident I know what the issue is, based on my prior encounters with it, but not confident what would be the optimal solution while working with Vite and the vite-plugin-react. Sounds like by adding babel into the mix I lose a lot of the speed gained by ESModules. Any advice or guidance would be greatly appreciated, and if code samples would be helpful I can try and provide those.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions