react-leaflet:Module parse failed: Unexpected token (10:41)

How to fix error “Failed to compile : ./node_modules/@react-leaflet/core/esm/path.js 10:41 Module parse failed: Unexpected token (10:41)”

https://stackoverflow.com/questions/67552020/how-to-fix-error-failed-to-compile-node-modules-react-leaflet-core-esm-pat

https://github.com/PaulLeCam/react-leaflet/issues/877

Answers:

If anyone is having issues with this make sure that your bundling tool is able to handle the nullish coalescing operator.

For babel you can use the @babel/plugin-proposal-nullish-coalescing-operator. Although make sure that you don't exclude node_modules in the rule. (This should be included in @babel/preset-env from the documentation)

It is related to facebook/create-react-app#9468 for those using CRA

@Arodriguez14 This is that most people will exclude node_modules when bundling (correctly). This means that the ?? in the project causes issues as the bundler doesn't know what to do with it. If you allow the rule (babel-loader for webpack for example) to run with node_modules too you should be ok (providing you don't need the plugin).

Ideally, this wouldn't be the case. By adding --plugins @babel/plugin-proposal-nullish-coalescing-operator to the babel cli script that is run when generating the esm module this would mean that your bundler would not need to include this module. @PaulLeCam is this something that could be added?

But if CRA?

I mean sure maybe there is something else? But could also be that CRA is excluding node_modules meaning that it is a similar situation right? Guess what I'm saying is more of an observation rather than the definite solution

facebook/create-react-app#9468 (comment) worked for me

原文地址:https://www.cnblogs.com/2008nmj/p/15007657.html