Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read properties of undefined (reading: 'trim') #1290

Open
1982FenceHopper opened this issue May 30, 2024 · 0 comments
Open

Comments

@1982FenceHopper
Copy link

Explanation

Attempting to use ytdl-core within a Server API Route Handler results in the validation export of ytdl-core to stop functioning, due to the fact TypeScript is most likely not understanding the string trim() method, looks like its also not inferring types from the JSDoc comments.

What is supposed to happen

Information including formats on the specified link should be returned.

Stack Trace

TypeError: Cannot read properties of undefined (reading 'trim')
    at exports.validateID (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected]/node_modules/ytdl-core/lib/url-utils.js:75:44)
    at exports.getVideoID (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected]/node_modules/ytdl-core/lib/url-utils.js:58:15)
    at exports.<computed> [as getInfo] (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected]/node_modules/ytdl-core/lib/info.js:484:29)
    at POST (webpack-internal:///(rsc)/./src/app/api/fetchYouTubeAudio/route.ts:13:73)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/hopper/Code Projects (Ongoing)/Reaction Audio Player/reaction-audio-player/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:53446
    at async e_.execute (/home/hopper/Code Projects (Ongoing)/Reaction Audio Player/reaction-audio-player/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:44747)
    at async e_.handle (/home/hopper/Code Projects (Ongoing)/Reaction Audio Player/reaction-audio-player/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:54700)
    at async doRender (/home/hopper/Code Projects (Ongoing)/Reaction Audio Player/reaction-audio-player/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:1377:42)
    at async cacheEntry.responseCache.get.routeKind (/home/hopper/Code Projects (Ongoing)/Reaction Audio Player/reaction-audio-player/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:1599:28)
    at async DevServer.renderToResponseWithComponentsImpl (/home/hopper/Code Projects (Ongoing)/Reaction Audio Player/reaction-audio-player/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:1507:28)
    at async DevServer.renderPageComponent (/home/hopper/Code Projects (Ongoing)/Reaction Audio Player/reaction-audio-player/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:1924:24)
    at async DevServer.renderToResponseImpl (/home/hopper/Code Projects (Ongoing)/Reaction Audio Player/reaction-audio-player/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:1962:32)
    at async DevServer.pipeImpl (/home/hopper/Code Projects (Ongoing)/Reaction Audio Player/reaction-audio-player/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:920:25)
    at async NextNodeServer.handleCatchallRenderRequest (/home/hopper/Code Projects (Ongoing)/Reaction Audio Player/reaction-audio-player/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/next-server.js:272:17)
    at async DevServer.handleRequestImpl (/home/hopper/Code Projects (Ongoing)/Reaction Audio Player/reaction-audio-player/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:816:17)
    at async /home/hopper/Code Projects (Ongoing)/Reaction Audio Player/reaction-audio-player/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/dev/next-dev-server.js:339:20
    at async Span.traceAsyncFn (/home/hopper/Code Projects (Ongoing)/Reaction Audio Player/reaction-audio-player/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/trace/trace.js:154:20)
    at async DevServer.handleRequest (/home/hopper/Code Projects (Ongoing)/Reaction Audio Player/reaction-audio-player/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/dev/next-dev-server.js:336:24)
    at async invokeRender (/home/hopper/Code Projects (Ongoing)/Reaction Audio Player/reaction-audio-player/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/lib/router-server.js:174:21)
    at async handleRequest (/home/hopper/Code Projects (Ongoing)/Reaction Audio Player/reaction-audio-player/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/lib/router-server.js:353:24)
    at async requestHandlerImpl (/home/hopper/Code Projects (Ongoing)/Reaction Audio Player/reaction-audio-player/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/lib/router-server.js:377:13)
    at async Server.requestListener (/home/hopper/Code Projects (Ongoing)/Reaction Audio Player/reaction-audio-player/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/lib/start-server.js:141:13)

Code Snippet (Next.js App Directory, Route Handler)

import { NextResponse, NextRequest } from "next/server";
import ytdl from "ytdl-core";

export async function POST(req: NextRequest, res: NextResponse) {
  const body = await req.json();
  const url = await body["url"];

  const info = await ytdl.getInfo(url);

  return NextResponse.json({ videoInfo: info }, { status: 200 });
}

Environment

  • ytdl-core 4.11.5
  • Next.js 14.2.3 (With TypeScript)
  • Node.js 20.13.1 LTS
  • Linux (Windows WSL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant