简体   繁体   中英

react leaflet Module parse failed: Unexpected token (10:39)

Failed to compile.

./node_modules/@react-leaflet/core/lib/path.js 10:39
Module parse failed: Unexpected token (10:39) You may need an appropriate loader to handle this file type. | useEffect(function updatePathOptions() { | if (props.pathOptions.== optionsRef.current) {

 var options = props.pathOptions?? {};

| element.instance.setStyle(options); | optionsRef.current = options;

I had the same problem. After some research, I found the below answers, which helped me fix them.

  1. First, check if your react version matches "react-leaflet" version.
    • For example in "react-leaflet" version 4.x, React v18 and Leaflet v1.8 are now required as peer dependency. ref.
  2. Update browserslist in package.json to this:
...    
    "browserslist": [
       ">0.2%",
      "not dead",
      "not op_mini all"
    ],
...
  1. Delete .cache directory in node_modules and start over.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM