Hypfer / ICantBelieveItsNotValetudo

A Valetudo companion service which renders maps to pngs
Apache License 2.0
129 stars 80 forks source link

TypeError: mapData.layers.flatMap is not a function #63

Closed Benni620 closed 2 years ago

Benni620 commented 3 years ago

After a new install of ICantBelieveItsNotValetudo i´ve got this error:

npm start                                                                                                                                                                          
> i-cant-believe-its-not-valetudo@2021.6.0 start
> node app.js

[2021-06-29T12:36:08.133Z] [INFO] Loading configuration file: /home/raspberrypi/valetudomap/ICantBelieveItsNotValetudo/config.json
[2021-06-29T12:36:08.409Z] [INFO] Connecting to MQTT broker...
[2021-06-29T12:36:08.484Z] [INFO] Webserver running on port 3003
[2021-06-29T12:36:08.518Z] [INFO] Connected to MQTT broker.
/home/raspberrypi/valetudomap/ICantBelieveItsNotValetudo/lib/MapDrawer.js:49
            x1: Math.min(...mapData.layers.flatMap(layer => layer.dimensions.x.min)),
                                           ^

TypeError: mapData.layers.flatMap is not a function
    at MapDrawer.updateMap (/home/raspberrypi/valetudomap/ICantBelieveItsNotValetudo/lib/MapDrawer.js:49:44)
    at Timeout.MqttClient.setInterval [as _onTimeout] (/home/raspberrypi/valetudomap/ICantBelieveItsNotValetudo/lib/MqttClient.js:90:28)
    at ontimeout (timers.js:436:11)
    at tryOnTimeout (timers.js:300:5)
    at listOnTimeout (timers.js:263:5)
    at Timer.processTimers (timers.js:223:10)

Is there a solution for this problem? It is installed on a Raspberry Pi 3B. The Pi is allso used for Openhab, Grafana, Influxdb and Pihole. I hope the problem is not related to the other software.

Roborock S5 Valetudo 2021.04.0

philmottin commented 3 years ago

I'm running on docker, but I had the same error. I notice it only happened after I created my own config.js and mapped the file into the container, as the readme says.

So I clean up everything and this time I created the config.js based on the default_config.json located in lib/res. All good now.

I notice the config.js example on the readme has some properties missing, try this template located in lib/res. It worked for me.

{
  "mapSettings": {
    "drawPath": true,
    "draw Charger": true,
    "draw Robot": true,
    "scale": 2,
    "rotate": 0,
    "colors": {
      "floor": "#0076ff",
      "obstacle": "#52aeff",
      "path": "#ffffff"
    }
  },
  "mqtt": {
    "identifier": "rockrobo",
    "topicPrefix": "valetudo",
    "autoconfPrefix": "homeassistant",
    "broker_url": "mqtt://user:pass@foobar.example",
    "caPath": "",
    "mapDataTopic": "valetudo/robot/MapData/map-data",
    "minMillisecondsBetweenMapUpdates": 10000,
    "publishMapImage": true
  },
  "webserver": {
    "enabled": true,
    "port": 3000
  },
  "logLevel": "info"
}
cweber9843 commented 3 years ago

I can confirm the error, same TypeError as @Benni620 mentioned. Unfortunately the solution suggested by @philmottin did not work for me.

I did notice npm giving a warning on a lock file:

npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. 
I'll try to do my best with it!`

Deleting the lock file and running npm install does not lead to this error - so I guess this is not related? (npm also claims that the error is not related:)

npm ERR! Failed at the i-cant-believe-its-not-valetudo@2021.8.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

I am running OH3 on a dedicated laptop, no docker. RoborockS5 Valetudo 2021.09.1 ICantBelieveItsNotValetudo 2021.08.0

Benni620 commented 2 years ago

So now a few weeks later.. I´ve updated a lot of, the robot, Icbinv and NodeJS. Now this error is gone. But now I have other new problems..

But perhaps you have more luck than I and it runs.

Hypfer commented 2 years ago

Array.prototype.flatMap()

needs at least nodejs 11