zS1L3NT / ts-npm-ytmusic-api

A type-safe and basic YouTube Music API wrapper
https://npmjs.com/package/ytmusic-api
GNU General Public License v3.0
81 stars 17 forks source link

[BUG]: TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "X-Goog-Visitor-Id" #5

Closed tim-the-arcane closed 2 years ago

tim-the-arcane commented 2 years ago

Please describe the current behaviour of the code.

I copy pasted the code snippets from the Usage section of the documentation:

import express from "express";
import YTMusic from "ytmusic-api";
const router = express.Router();

router.post("/", async (req, res) => {
  const { query } = req.body;

  console.log("/search", req.body);

  const ytMusic = await new YTMusic().initialize();

  ytMusic.searchSongs(query).then((songs) => {
    console.log(songs);
  });
});
export default router;

When requesting the search route via REST I get this error in the Express logs:

### Search song
POST http://localhost:4001/search
Content-Type: application/json

{
  "query": "fjaak"
}

TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "X-Goog-Visitor-Id"

Please describe the expected behaviour of the code.

I expected that the route logs the search results instead of an error

What are the steps to reproduce the error?

Pretty much just follow the steps in the documentation

Additional Information

node:internal/errors:464
    ErrorCaptureStackTrace(err);
    ^

TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "X-Goog-Visitor-Id"
    at ClientRequest.setHeader (node:_http_outgoing:579:3)
    at new ClientRequest (node:_http_client:256:14)
    at Object.request (node:https:353:10)
    at RedirectableRequest._performRequest (******-backend/node_modules/follow-redirects/index.js:279:24)
    at new RedirectableRequest (******-backend/node_modules/follow-redirects/index.js:61:8)
    at Object.request (******-backend/node_modules/follow-redirects/index.js:511:14)
    at dispatchHttpRequest (******-backend/node_modules/axios/lib/adapters/http.js:262:25)
    at new Promise (<anonymous>)
    at httpAdapter (******-backend/node_modules/axios/lib/adapters/http.js:49:10)
    at dispatchRequest (******-backend/node_modules/axios/lib/core/dispatchRequest.js:58:10) {
  code: 'ERR_HTTP_INVALID_HEADER_VALUE'
}
[nodemon] app crashed - waiting for file changes before starting...
tim-the-arcane commented 2 years ago

Thank you very much for reworking the youtube-music-api! I was so excited when I saw it. I hope we can resolve this issue.