我的github
posts - 3243,  comments - 42,  views - 158万

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

posted on   XiaoNiuFeiTian  阅读(701)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
历史上的今天:
2017-07-13 Google Tango service outdated谷歌Tango的服务过时了
2017-07-13 Hello_Motion_Tracking 任务一:Project Tango采集运动追踪数据
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示