-
Notifications
You must be signed in to change notification settings - Fork 893
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
Nullish coalescing operator makes package incompatible with webpack 4 #883
Comments
I'm having the same issue, but i have the config on babel to handle nullish coalescing operator from months ago. and doesn't work for this library. |
Having the same issue here, it's causing me to have to add quite a few workarounds to my configurations. I think it's negligible in terms of bundle size to just compile this down. I can take a look tonight and submit a PR. Edit: Nevermind, it looks like @PaulLeCam has rejected a PR for this before. @PaulLeCam it is not standard practice for packages to have the latest ES syntax because bundlers like webpack are configured by default to not run babel on |
I can confirm this with FuseBox 3 as well (It's using Acorn 5.7). |
Also this doesn't exist only with Webpack. Babel on Node 12 can have the issue in certain cases. I have some code that dynamically imports react leaflet (since I need to server-side render) and when I run my tests in node < 14 it's not able to run. |
reverting to |
I've opened a PR here: #885 |
None of the comments above worked for me. Changing versions in package.json solved issue.
use npm install instead of yarn install. |
Be aware that this is not a solution. It is a workaround that prevents installing the |
As a temporary workaround you can specify "@react-leaflet/core": "1.0.2" as dependency and specify also |
For next.js project you can use future: {
webpack5: true
}, flag inside your next.config.js file |
Need to BABELify both packages customize-cra (config-overrides.js) babelInclude([ for images |
A compatibility issue in react-leaflet prevents a project created with CRA from compiling. Applied the fix described in facebook/create-react-app#9468 (comment) Also, please see PaulLeCam/react-leaflet#883
@PaulLeCam why was this closed? |
Still have this issue with v3.2.2Real blocker for us, please fix this!!!! Debugging this looks like the The building code of this repo is transpiring the nullish operator, but in npm's package it is still there. |
See #885 (comment) |
@PaulLeCam while I don't agree with your take on this, would it not save you more work by adding this to the README/docs/wiki at least? Feels like this is coming up over and over again and no one understands why. |
Many of my students are having problems using react-leaflet because of issues reported in PaulLeCam#877, PaulLeCam#880 and PaulLeCam#883. It seems to be a common problem: https://stackoverflow.com/questions/67552020/how-to-fix-error-failed-to-compile-node-modules-react-leaflet-core-esm-pat and there is even a video about the solution in YouTube with more than 1500 views: https://youtu.be/tFqj-JKYr4M
In anticipation of the v18 update of the react package. The addition of a specific configuration is required with webpack v4 since version 3 of react-leaflet. See: PaulLeCam/react-leaflet#883
Hey,
first of all - thanks a lot for working on this library, we really enjoy using it!
Unfortunately, the recently released version 3.2.0 of this package breaks our build. I am aware that this was already reported in #881, #882, #879, #877 and #880, but I would like to add some additional information here why this is happening and what the possible solutions are. For completion, the build in our project errors with the following message:
Why is it happening
Version 3.2.0 of this package uses the nullish coalescing operator in the code that is published to npm. As this operator is supported by most modern browsers, babel does not transpile it away when defining a fairly modern set of browsers in the
browserlist
used by the project.Unfortunately, while supported by modern browsers, the nullish coalescing operator is not supported by webpack 4 (webpack/webpack#10227). The reason for this is that support for the operator was only added in acorn 7 (acornjs/acorn#890), but webpack 4 uses (and probably will always use) acorn 6.
In conclusion, this means that this package is currently not compatible with webpack 4 without additional configuration because it includes the nullish coalescing operator in the code that is published to npm. Webpack 4 is still used by popular projects such as
create-react-app
.How to fix it in the library
The most effective solution for this problem would be publishing a new version of the package that does not include the nullish coalescing operator. This is either possible by adjusting the code of the package like proposed in #880 or by adjusting the
.babelrc.js
file in this repository transpile this operator in the code that is published to npm.This solution would allow all projects that are encountering the problem to fix it by simply updating the package.
How to fix it in your project
Its possible to prevent the problem in your project by configuring babel to always transpile the nullish coalescing operator regardless of the targeted browsers by enabling the
@babel/plugin-proposal-nullish-coalescing-operator
plugin: https://babeljs.io/docs/en/babel-plugin-proposal-nullish-coalescing-operatorThis plugin will transpile the nullish coalescing operator before the files are processed by webpack and therefore prevent the error in your project.
Other workarounds
A lot of comments suggest to adjust the targeted browsers to include older browsers like described in facebook/create-react-app#9468 (comment)
This fix will indirectly enable the
@babel/plugin-proposal-nullish-coalescing-operator
plugin. The disadvantage of this method is that the size of the build will increase because the whole codebase is transpiled to be fully compatible with older browsers.Other comments like #879 (comment) suggest to skip the 3.2.0 version of the package. This is only a temporary fix and things will break again if the next version of the package still contains the nullish coalescing operator in the published code.
The text was updated successfully, but these errors were encountered: