问题:
react依赖包问题

error  in ./node_modules/@react-leaflet/core/esm/path.js

Module parse failed: Unexpected token (10:41)
You may need an appropriate loader to handle this file type, currently no loaders areo process this file. See https://webpack.js.org/concepts#loaders
|   useEffect(function updatePathOptions() {
|     if (props.pathOptions !== optionsRef.current) {
>       const options = props.pathOptions ?? {};
|       element.instance.setStyle(options);
|       optionsRef.current = options;

 @ ./node_modules/@react-leaflet/core/esm/index.js 15:0-56 15:0-56 15:0-56
 @ ./node_modules/react-leaflet/esm/ZoomControl.js
 @ ./node_modules/react-leaflet/esm/index.js
 @ ./src/pages/RoadNetwork/RegionAnalysis/Travel/index.tsx
 @ ./src/.umi/core/routes.ts
 @ ./src/.umi/umi.ts
 @ multi ./node_modules/umi/node_modules/@umijs/preset-built-in/bundled/@pmmmwh/reactack-plugin/client/ReactRefreshEntry.js ./src/.umi/umi.ts

解决:
可能当前版本和环境 " ?? " 不能识别,所以把用函数将??替换掉即可。

function change(a, b) {
    return a !== undefined && a !== null ? a : b
  }

替换前

export function usePathOptions(element, props) {
  const optionsRef = useRef();
  useEffect(function updatePathOptions() {
    if (props.pathOptions !== optionsRef.current) {
      const options = props.pathOptions ?? {};
      element.instance.setStyle(options);
      optionsRef.current = options;
    }
  }, [element, props]);
}

替换后

export function usePathOptions(element, props) {
  const optionsRef = useRef();
  function change(a, b) {
    return a !== undefined && a !== null ? a : b
  }
  useEffect(function updatePathOptions() {
    if (props.pathOptions !== optionsRef.current) {
      const options = change(props.pathOptions, {});
      element.instance.setStyle(options);
      optionsRef.current = options;
    }
  }, [element, props]);
}
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐