Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Help with import of youtube-transcript #758

Unanswered
mandric asked this question in Q&A
Discussion options

Hello, esm.sh looks amazing and I am trying to use it for the first time.

I thought it would be cool to try and get youtube-transcript running on a browser, but it's failing and now sure why.

Here's the example that works in node.js using a file with .mjs extension:

const vidId = "DibH4GRRWQU"
//var yt = require("youtube-transcript");
//yt.YoutubeTranscript.fetchTranscript(vidId).then(console.log);
import { YoutubeTranscript } from "youtube-transcript";
YoutubeTranscript.fetchTranscript(vidId).then(console.log);

Here is my html that does not work:

<script type="importmap">
 {
 "imports": {
 "centra": "https://esm.sh/phin@2.6.0",
 "phin": "https://esm.sh/phin@3.5.0",
 "local-youtube-transcript": "./node_modules/youtube-transcript/dist/youtube-transcript.esm.js",
 "youtube-transcript": "https://esm.sh/youtube-transcript@1.0.6"
 }
 }
</script>
<script type="module">
 import { YoutubeTranscript } from "youtube-transcript";
 YoutubeTranscript.fetchTranscript("DibH4GRRWQU").then(console.log);
</script>

The error is:

Screenshot 2023年11月15日 at 1 05 57 PM

Screenshot 2023年11月15日 at 1 04 30 PM

I also pushed a little test repo here: https://github.com/mandric/video-transcripts

I also tried with a local build of youtube-transcript, but it fails with the same error.

Should I reach out to the youtube-transcript module author?

Thanks for your help and amazing project!

You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

please try https://esm.sh/youtube-transcript@1.0.6?bundle, i guess some of deps of phin are cjs that can not be convered by the server correctly.

You must be logged in to vote
1 reply
Comment options

I tried using ?bundle and the browser gave a similar error, even referencing the same line in the error, except instead of z is not a constructor I got U is not a constructor. I also tested with Deno and it works fine. I think it's only an issue in the browser. I will update my repo with more tests and examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /