Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. (gelöst) NPM-Modul "node-fetch" in der Javascript-Instanz

    NEWS

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    (gelöst) NPM-Modul "node-fetch" in der Javascript-Instanz

    This topic has been deleted. Only users with topic management privileges can see it.
    • ice987
      ice987 @paul53 last edited by

      @paul53

      This module was converted to be a ESM only package in version 3.0.0-beta.10. node-fetch is an ESM-only module - you are not able to import it with require. We recommend you stay on v2 which is built with CommonJS unless you use ESM yourself. We will continue to publish critical bug fixes for it.

      paul53 1 Reply Last reply Reply Quote 0
      • paul53
        paul53 @ice987 last edited by paul53

        @ice987
        Gerade bei mir getestet:
        node-fetch wurde unter /opt/iobroker/node_modules/iobroker.javascript/node_modules installiert, require will aber unter /opt/iobroker/node_modules darauf zugreifen, wo es nicht installiert ist.

        ice987 1 Reply Last reply Reply Quote 0
        • ice987
          ice987 @paul53 last edited by

          @paul53 sagte in NPM-Module in der Javascript instanz:

          Ich meinte: Aus der Konfiguration löschen, speichern und wieder eintragen - also noch mal die Installation versuchen.

          nun funktioniert es!

          Vielen Dank!

          1 Reply Last reply Reply Quote 0
          • AlCalzone
            AlCalzone Developer @ice987 last edited by

            @ice987 sagte in (gelöst) NPM-Module in der Javascript instanz:

            iobroker.inst@2.0.3 /opt/iobroker
            ├─┬ iobroker.javascript@5.2.8
            │ └── node-fetch@3.0.0  deduped
            └── node-fetch@3.0.0
            

            Hast du zufällig node-fetch mal innerhalb /opt/iobrokerhändisch nachinstalliert?
            Das sieht aus, als würde es auch in /opt/iobroker/package.json stehen, wo es definitiv nicht hingehört.

            ice987 1 Reply Last reply Reply Quote 0
            • ice987
              ice987 @AlCalzone last edited by ice987

              @alcalzone
              leider ist das so, ja.

              AlCalzone 1 Reply Last reply Reply Quote 0
              • AlCalzone
                AlCalzone Developer @ice987 last edited by

                @ice987 Dann am besten mal entfernen, das dürfte nämlich die Ursache für solche Probleme sein.

                cd /opt/iobroker
                npm uninstall node-fetch
                
                ice987 1 Reply Last reply Reply Quote 0
                • ice987
                  ice987 @AlCalzone last edited by ice987

                  @alcalzone

                  root@iobroker-v510:/opt/iobroker# cd /opt/iobroker
                  root@iobroker-v510:/opt/iobroker# npm uninstall node-fetch
                  npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/fsevents):
                  npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
                  
                  removed 19 packages and audited 1289 packages in 35.686s
                  
                  102 packages are looking for funding
                    run `npm fund` for details
                  
                  found 64 vulnerabilities (5 low, 21 moderate, 35 high, 3 critical)
                    run `npm audit fix` to fix them, or `npm audit` for details
                  root@iobroker-v510:/opt/iobroker# npm ls node-fetch
                  iobroker.inst@2.0.3 /opt/iobroker
                  └─┬ iobroker.javascript@5.2.8
                    └── node-fetch@3.0.0
                  

                  die "Zusätzlichen NPM-Module" im Javascript-Adapter wurden vorher entfernt und sind aktuell nicht drin. Ist die Installation so nun in Ordnung?

                  Das Skript scheint zu funktionieren...

                  AlCalzone 1 Reply Last reply Reply Quote 0
                  • AlCalzone
                    AlCalzone Developer @ice987 last edited by

                    @ice987 Das sieht besser aus. Wenn du solche Probleme künftig vermeiden willst, am besten noch all die anderen Pakete deinstallieren, die unnötigerweise in /opt/iobroker/package.json stehen. Da sollten ausschließlich dependencies drin sein, die mit iobroker. oder @iobroker/ beginnen.

                    Vorsichtshalber mal ein Backup vorher fahren 🙂

                    ice987 1 Reply Last reply Reply Quote 0
                    • ice987
                      ice987 @AlCalzone last edited by

                      @alcalzone
                      wunderbar!

                      hab' gerade gekuckt in /opt/iobroker/package.json: alles fängt mit iobroker. oder @iobroker/ an ausser:

                      "colors": "^1.3.3",
                      "fs-extra": "^7.0.1"
                      "iobroker": "^2.0.3",
                      "semver": "^5.6.0",
                      "yargs": "^7.0.2"
                      

                      alles stehen lassen?

                      AlCalzone 1 Reply Last reply Reply Quote 0
                      • AlCalzone
                        AlCalzone Developer @ice987 last edited by

                        @ice987 iobroker drin lassen. Der Rest dürfte raus können.

                        ice987 1 Reply Last reply Reply Quote 0
                        • ice987
                          ice987 @AlCalzone last edited by ice987

                          @alcalzone
                          ok, hab alles gelistete entfernt (ausser iobroker). Nun habe ich aber erneut das Problem mit dem Error:

                          Module sind wie folgt eingetragen:
                          c91a6e3b-8f85-42ea-9b8c-2bcc00fca5a2-image.png

                          error wie folgt:

                          14:52:47.875	error	javascript.2 (185) script.js.08_Wetterstation.082_Meteoblue: Error: Cannot find module '/opt/iobroker/node_modules/iobroker.javascript/lib/../../node-fetch'
                          
                          root@iobroker-v510:/opt/iobroker# npm ls node-fetch
                          iobroker.inst@2.0.3 /opt/iobroker
                          └─┬ iobroker.javascript@5.2.8
                            └── node-fetch@3.0.0
                          
                          AlCalzone paul53 2 Replies Last reply Reply Quote 0
                          • AlCalzone
                            AlCalzone Developer @ice987 last edited by

                            @ice987 entferne es mal, starte den Adapter neu, dann füge es wieder hinzu.

                            ice987 1 Reply Last reply Reply Quote 0
                            • ice987
                              ice987 @AlCalzone last edited by ice987

                              @alcalzone
                              ich habe alles hier
                              31b0f607-d79f-4326-b9dd-dbb2c8fc8cd9-image.png
                              entfernt, Instanz neu gestartet, der error bleibt. node-fetch wieder hinzugefügt, Instanz heu gestartet, Fehler bleibt.

                              1 Reply Last reply Reply Quote 0
                              • paul53
                                paul53 @ice987 last edited by

                                @ice987 sagte: error wie folgt:

                                Wie ist es in das Skript eingebunden?

                                ice987 1 Reply Last reply Reply Quote 0
                                • ice987
                                  ice987 @paul53 last edited by ice987

                                  @paul53

                                  aktuell (zu Testzwecken) nur so:

                                  const fetch = require('node-fetch');
                                  

                                  welches bereits den Fehler ergibt:

                                  paul53 1 Reply Last reply Reply Quote 0
                                  • paul53
                                    paul53 @ice987 last edited by paul53

                                    @ice987
                                    require erwartet es im Verzeichnis /opt/iobroker/node_modules, wo es offenbar nicht (mehr) installiert ist.

                                    Error: Cannot find module '/opt/iobroker/node_modules/iobroker.javascript/lib/../../node-fetch'
                                    

                                    import reagiert anders.

                                    1 Reply Last reply Reply Quote 0
                                    • AlCalzone
                                      AlCalzone Developer last edited by AlCalzone

                                      Dann ist da im Adapter irgendwas faul...
                                      import wird unter der Haube in require umgeschrieben, sollte sich also gleich verhalten.

                                      @ice987 Probier mal als Workaround:

                                      cd /opt/iobroker/node_modules/iobroker.javascript
                                      npm install --production
                                      
                                      paul53 1 Reply Last reply Reply Quote 0
                                      • ice987
                                        ice987 last edited by ice987

                                        @paul53
                                        so hätte ich die Fehlermeldung auch interpretiert. Da hab' ich's manuell probiert, was funktionierte, jedoch nicht der "korrekten Installation" entspricht...

                                        @AlCalzone

                                        cd /opt/iobroker/node_modules/iobroker.javascript
                                        npm install --production
                                        

                                        habe ich ausgeführt: fehler bleibt:

                                        Script nur eine Zeile:

                                        const fetch = require('node-fetch');
                                        

                                        fehler:

                                        15:20:40.276	error	javascript.2 (1358) script.js.08_Wetterstation.Skript_1: Error: Cannot find module '/opt/iobroker/node_modules/iobroker.javascript/lib/../../node-fetch'
                                        

                                        wenns was zur Sache tut: ioBroker läuft auf einem QNAP im Container, unter dem offiziellen Dockerimage von Buanet.

                                        1 Reply Last reply Reply Quote 0
                                        • paul53
                                          paul53 @AlCalzone last edited by

                                          @alcalzone sagte: Probier mal als Workaround:

                                          cd /opt/iobroker/node_modules/iobroker.javascript
                                          npm install --production
                                          

                                          Dorthin hat es der Javascript-Adapter installiert. Es wird dort aber nicht von require gefunden.

                                          1 Reply Last reply Reply Quote 0
                                          • AlCalzone
                                            AlCalzone Developer last edited by

                                            Laut https://github.com/ioBroker/ioBroker.javascript/blob/1a05db402d3c5ad83623825734141a22c34e04b9/lib/sandbox.js#L410-L423 sollte zuerst

                                            /opt/iobroker/node_modules/iobroker.javascript/node_modules/node-fetch
                                            

                                            und anschließend

                                            /opt/iobroker/node_modules/node-fetch
                                            

                                            versucht werden.
                                            In diesem Fall würde das bedeuten, dass node-fetch sich weder im Unterordner, noch in der übergeordneten Struktur befindet.

                                            @ice987
                                            Was kommt hier raus?

                                            cd /opt/iobroker
                                            find -iname node-fetch
                                            
                                            paul53 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            827
                                            Online

                                            31.7k
                                            Users

                                            79.8k
                                            Topics

                                            1.3m
                                            Posts

                                            5
                                            39
                                            3284
                                            Loading More Posts
                                            • Oldest to Newest
                                            • Newest to Oldest
                                            • Most Votes
                                            Reply
                                            • Reply as topic
                                            Log in to reply
                                            Community
                                            Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                                            The ioBroker Community 2014-2023
                                            logo