-
-
Notifications
You must be signed in to change notification settings - Fork 192
-
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!
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 1 reply
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
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.
Beta Was this translation helpful? Give feedback.