ebody: nodejs ist installiert - npm start zeigt aber Fehler (Update)

Beitrag lesen

  1. Frage: Hast Du in der Datei package-lock.json einen Eintrag wie diesen?

Ja. Aber dennoch gut zu wissen.

Zeige mal die alle Ausgaben des Befehls.

npm run open


> muster-oop@1.0.0 open D:\projekte\spielplatz\js\muster-oop
> concurrently "http-server -a localhost -p 8080" "open http://localhost:8080/index.html"

[1] Der Befehl "open" ist entweder falsch geschrieben oder
[1] konnte nicht gefunden werden.
[1] open http://localhost:8080/index.html exited with code 1
[0] Starting up http-server, serving ./
[0]
[0] http-server version: 14.1.1
[0]
[0] http-server settings: 
[0] CORS: disabled
[0] Cache: 3600 seconds
[0] Connection Timeout: 120 seconds
[0] Directory Listings: visible
[0] AutoIndex: visible
[0] Serve GZIP Files: false
[0] Serve Brotli Files: false
[0] Default File Extension: none
[0]
[0] Available on:
[0]   http://localhost:8080
[0] Hit CTRL-C to stop the server
[0]

Registriere in der package.json zusätzlich

Habe ich gemacht, so richtig?

{
  "name": "muster-oop",
  "version": "1.0.0",
  "description": "",
  "main": "index.html",
  "serverbrowser": "concurrently \"http-server -a localhost -p 1234\" \"http-server http://localhost:1234/index.html\"",
  "scripts": {
    "open": "concurrently \"http-server -a localhost -p 1234\" \"open http://localhost:1234/index.html\""
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "concurrently": "^7.3.0",
    "http-server": "^14.1.1"
  },
  "dependencies": {
    "open": "^8.4.0"
  }
}

(Gleiche) Fehlermeldung erscheint immer noch, wenn ich npm run open ausführe. Führe ich npm run serverbrowser aus erscheint

npm ERR! missing script: serverbrowser

package.json habe ich noch mal angepasst und...

"serverbrowser": "concurrently \"http-server -a localhost -p 1234\" \"http-server http://localhost:1234/index.html\""

...ins scripts Objekt eingefügt.

{
  "name": "muster-oop",
  "version": "1.0.0",
  "description": "",
  "main": "index.html",
  "scripts": {
    "open": "concurrently \"http-server -a localhost -p 1234\" \"open http://localhost:1234/index.html\"",
    "serverbrowser": "concurrently \"http-server -a localhost -p 1234\" \"http-server http://localhost:1234/index.html\""
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "concurrently": "^7.3.0",
    "http-server": "^14.1.1"
  },
  "dependencies": {
    "open": "^8.4.0"
  }
}
npm run serverbrowser

ausgeführt und erhalte keine Fehlermeldung:

[0] Starting up http-server, serving ./
[1] Starting up http-server, serving http://localhost:1234/index.html
[0]
[0] http-server version: 14.1.1
[0]
[0] http-server settings: 
[0] CORS: disabled
[0] Cache: 3600 seconds
[0] Connection Timeout: 120 seconds
[0] Directory Listings: visible
[0] AutoIndex: visible
[0] Serve GZIP Files: false
[0] Serve Brotli Files: false
[0] Default File Extension: none
[0]
[0] Available on:
[0]   http://localhost:1234
[0] Hit CTRL-C to stop the server
[0]
[1]
[1] http-server version: 14.1.1
[1]
[1] http-server settings: 
[1] CORS: disabled
[1] Cache: 3600 seconds
[1] Connection Timeout: 120 seconds
[1] Directory Listings: visible
[1] AutoIndex: visible
[1] Serve GZIP Files: false
[1] Serve Brotli Files: false
[1] Default File Extension: none
[1]
[1] Available on:
[1]   http://192.168.178.21:8080
[1]   http://127.0.0.1:8080
[1] Hit CTRL-C to stop the server
[1]

Gebe ich http://localhost:1234/ in den Browser ein oder führe in VS Code "Run and Debug" aus, öffnet sich die index.html.

Vielen Dank für die Hilfe, jetzt funktioniert es.

Gruß ebody