我刚刚开始一个全新的项目create-react-app
并设置react-leaflet
正如他们的文档所建议的here https://react-leaflet.js.org/docs/start-installation.
我正在尝试使用这个例子 https://react-leaflet.js.org/docs/start-setup检查它是否一切正常,但随后我收到以下错误:
./node_modules/@react-leaflet/core/esm/path.js 10:41
Module parse failed: Unexpected token (10:41)
File was processed with these loaders:
* ./node_modules/react-scripts/node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| useEffect(function updatePathOptions() {
| if (props.pathOptions !== optionsRef.current) {
> const options = props.pathOptions ?? {};
| element.instance.setStyle(options);
| optionsRef.current = options;
好像react-scripts
无法处理react-leaflet
文件。
有人可以帮助我理解为什么会发生这种情况以及如何解决它吗?
在阅读了所有博客上的相关内容后,我得出的结论是:这是因为新版本的react-leaflet。我遇到了同样的问题,这是我摆脱错误的方法:
打开你的包.json file
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
将其替换为以下几行:
"browserslist": [
">0.2%",
"not dead",
"not op_mini all"
],
另一种方法是在 package.json 文件中添加以下行:
"react-leaflet": ">=3.1.0 <3.2.0 || ^3.2.1",
"@react-leaflet/core": ">=1.0.0 <1.1.0 || ^1.1.1"
- 这会skip新发布的版本@react-leaflet/核心包 https://react-leaflet.js.org/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)