ybd-project / ytdl-core

Fast and secure YouTube downloader for JavaScript and TypeScript
MIT License
28 stars 5 forks source link

__imported__module__ is not a function #28

Closed kimgh06 closed 1 week ago

kimgh06 commented 2 months ago

Describe the bug

When trying to get audio with ytdl function, this bug appears on console. I change nothing on my code. Thus I tried to build with webpack after using turbopack in nextjs 14, also the bug appears.

Error Details (Log)

TypeError: (0 , TURBOPACKimportedmodule$5b$project$5d2f$node_modules$2f40$ybd$2d$project$2f$ytdl$2d$core$2f$package$2f$YtdlCore$2e$js$5b$app$2d$route$5d$$28$ecmascript$29$.default) is not a function at GET (C:\Users\ggh06\Documents\Github\Freetify.next\server\chunks\src_app83e26b..js:137:217)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:55759 at async eO.execute (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:46527) at async eO.handle (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:57093) at async doRender (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\base-server.js:1345:42) at async cacheEntry.responseCache.get.routeKind (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\base-server.js:1567:28) at async DevServer.renderToResponseWithComponentsImpl (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\base-server.js:1475:28) at async DevServer.renderPageComponent (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\base-server.js:1901:24) at async DevServer.renderToResponseImpl (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\base-server.js:1939:32) at async DevServer.pipeImpl (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\base-server.js:914:25) at async NextNodeServer.handleCatchallRenderRequest (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\next-server.js:272:17) at async DevServer.handleRequestImpl (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\base-server.js:810:17) at async C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\dev\next-dev-server.js:339:20 at async Span.traceAsyncFn (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\trace\trace.js:154:20) at async DevServer.handleRequest (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\dev\next-dev-server.js:336:24) at async invokeRender (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\lib\router-server.js:173:21) at async handleRequest (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\lib\router-server.js:350:24) at async requestHandlerImpl (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\lib\router-server.js:374:13) at async Server.requestListener (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\lib\start-server.js:141:13) GET /api/get_video?songId=1bp2IO61zbQrbWNmKKxg3f 500 in 10468ms GET /playlist/undefined 200 in 1138ms One Last Time Christopher Jacksons found "One Last Time" from HAMILTON TypeError: (0 , TURBOPACKimportedmodule$5b$project$5d2f$node_modules$2f40$ybd$2d$project$2f$ytdl$2d$core$2f$package$2f$YtdlCore$2e$js
$5b$app$2d$route$5d$$28$ecmascript$29$.default) is not a function at GET (C:\Users\ggh06\Documents\Github\Freetify.next\server\chunks\src_app83e26b..js:137:217)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:55759 at async eO.execute (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:46527) at async eO.handle (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:57093) at async doRender (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\base-server.js:1345:42) at async cacheEntry.responseCache.get.routeKind (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\base-server.js:1567:28) at async DevServer.renderToResponseWithComponentsImpl (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\base-server.js:1475:28) at async DevServer.renderPageComponent (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\base-server.js:1901:24) at async DevServer.renderToResponseImpl (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\base-server.js:1939:32) at async DevServer.pipeImpl (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\base-server.js:914:25) at async NextNodeServer.handleCatchallRenderRequest (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\next-server.js:272:17) at async DevServer.handleRequestImpl (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\base-server.js:810:17) at async C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\dev\next-dev-server.js:339:20 at async Span.traceAsyncFn (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\trace\trace.js:154:20) at async DevServer.handleRequest (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\dev\next-dev-server.js:336:24) at async invokeRender (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\lib\router-server.js:173:21) at async handleRequest (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\lib\router-server.js:350:24) at async requestHandlerImpl (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\lib\router-server.js:374:13) at async Server.requestListener (C:\Users\ggh06\Documents\Github\Freetify\node_modules\next\dist\server\lib\start-server.js:141:13)

Environment

develop environment: windows 11 deployment envirionment: vercel

ybd-project commented 2 months ago

Can you present the code importing ytdl-core? Please note that ytdl-core at this time is not guaranteed to work in the browser environment (including next.js).

kimgh06 commented 2 months ago

This code on serverless function, which does not work in the browser.

    try {
      if (url) {
        const poToken = process.env.NEXT_PUBLIC_POTOKEN
        const visitorData = process.env.NEXT_PUBLIC_VISITOR_DATA

        const stream = ytdl(`https://youtube.com/watch?v=${url}`, {
          filter: 'audioonly',
          quality: 'highestaudio',
          format: 'mp3',
          poToken,
          visitorData
        }).on('error', e => {
          console.log(e, 'error at get_video')
          throw e;
        });
        const response = new Response(stream);
        response.headers.set('content-type', 'audio/mp3')
        response.headers.set('connection', 'keep-alive');
        console.log('complete to send datas')
        return response
      }
      throw "no datas"
    } catch (e) {
      console.log(e)
      return NextResponse.json({ err: e }, { status: e.status || 500 })
    }
ybd-project commented 2 months ago

Thank you very much. We are currently discussing browser support at https://github.com/ybd-project/ytdl-core/issues/27. Do you need support?

kimgh06 commented 2 months ago

It's a good news. I am make the backend function for using as proxy. If there is the feature implement, I did not make the function when I make a service.

However the backend function takes on other role beside get the audio data.