How do I run a scrim on my local machine

I want to be able to run the scrims that I zip and download to my local machine.

I have always used MAMP to run my websites locally. However, this does not work for the scrims. For instance, with the scrim from The AI Engineer Path → Open-Source Models → Text To Speech With HuggingFace.js Inference the browser logs the error “TypeError: Module name, ‘@huggingface/inference’ does not resolve to a valid URL.”. This is due to the line “import { HfInference } from ‘@huggingface/inference’” in the scrim’s index.js file.

I have Node.js installed on my machine. Using Node I can successfully run a javascript file that contains the line “import { HfInference } from ‘@huggingface/inference’”. This is because I have used npm to install the module @huggingface/inference@3.4.0

I suspect that I need to involve Node in the running of the scrims, but I do not know how. I am a Node newbie. Would someone please help me?

@Tom_Chant

1 Like

Hey!

I recorded a Loom here which I think answers your question! Text To Speech With HuggingFace.js Inference - 1 March 2025 | Loom
Let me know if that works/doesn’t work and what problems you run into!

Hey Tom,

It worked, and yes that answered my question. I appreciate the time and energy that it took for you to make that Loom and I am grateful for it. Most excellent support guy!

I have two takeaways from this experience:

  1. Node modules cannot be executed by a browser (unless one wants to expend extra effort as discussed here: Running Node.js in web browsers | Techiediaries).

  2. In an actual production environment the Node module accessing code and the DOM accessing code have to be separated. This was demonstrated in The AI Engineer Path → Deployment using Cloudflare Workers and Pages.

Hopefully those takeaways are correct. Please comment if not.

============================================================

Now, there remains a mystery that, strictly speaking, does not need to be solved in order for me to be okay, but it would be nice.

The javascript code (index.js) of the HuggingFace textToSpeech scrim contains both Node module accessing code and DOM accessing code. According to takeaway two, VS Code would need to “magically” refactor index.js. Hmmm … What do you think, Tom?

Okay Tom, I am making progress.

First off, let me say that I have never used VsCode, albeit I have been intending to give it a try. Your Loom prompted me to install it. And, because you took me there, I naively assumed that VsCode was the solution; that it was somehow doing something that allows a javascript file (index.js) containing both Node module and DOM accessing code to be executed. Wrong. VsCode is not doing anything that I cannot alternately do from a command line.

Let me also say that, before Scrimba, I have never used Node.js and that I have never heard of vite (which from package.json appears to be some kind of build tool).

============================================================

So, now I am using a MacOS terminal window and am in the TextToSpeech directory.

If I enter the command “node index.js” then I get “ReferenceError: document is not defined”. Make sense given takeaway two above.

If I enter the command “npm start” (which runs vite) then Voila! I am good to go.

So, vite is the “magic sauce”. I will continue to investigate. Please feel free to chime in :slight_smile:

@Tom_Chant

Yes, scrims you download are indeed “bootstrapped” with Vite! If you first (in the terminal) do npm install and then node index.js it should run without vite.
Hope that helps!

Hi Tom,

Thanks for staying involved.

Node complains that there is no “document” which makes sense, right? The document (DOM) is a browser construct, right?

============ Here is the terminal output. =============

robertvaessen@Roberts-MacBook-Air TextToSpeech % npm install

up to date, audited 13 packages in 550ms

3 packages are looking for funding
run npm fund for details

found 0 vulnerabilities

robertvaessen@Roberts-MacBook-Air TextToSpeech % npm list
Scrim-s05qm3r@ /Users/robertvaessen/Library/Mobile Documents/com~apple~CloudDocs/Development/AI/local/huggingFace/TextToSpeech
├── @huggingface/inference@2.6.4
└── vite@6.2.0

robertvaessen@Roberts-MacBook-Air TextToSpeech % node index.js
Blob { size: 195165, type: ‘audio/flac’ }
file:///Users/robertvaessen/Library/Mobile%20Documents/com%7Eapple%7ECloudDocs/Development/AI/local/huggingFace/TextToSpeech/index.js:19
const audioElement = document.getElementById(‘speech’)
^

ReferenceError: document is not defined
at file:///Users/robertvaessen/Library/Mobile%20Documents/com%7Eapple%7ECloudDocs/Development/AI/local/huggingFace/TextToSpeech/index.js:19:22
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)

Node.js v23.6.0
robertvaessen@Roberts-MacBook-Air TextToSpeech %

Ah I fear I have muddied the waters but not fully understanding what you are doing! Is your end goal to have a node backend so you can deploy an app with the api hidden?

If not, with vite is the easiest way to go. You are absolutely right that you won’t be able to access the dom when working in the node environment (without vite or something similar) - to do that you would have to serve your html pages, CSS and JS (Scrimba course on doing that coming soon!).

Sorry, that was my bad for not thinking!

Thanks, Tom.

What I am trying to do is to insure that I know how to run the code that I am learning at Scrimba without Scrimba. My first step is to get it running on my own machine. After that, when I find myself with a “real project” to accomplish, I’ll be armed with the knowledge that will allow me to meet the needs of that project.

I must confess that I can become confused when faced with many new things all at once: scrims, Node, Huggingface, npm, Ollama, etc. For instance: I should have realized that I should have been using the command “npm start” instead of “node index.js”, and that doing so would bring this “vite thing” into the picture. I want to sincerely thank you for your patience with me in this regard since my primary issue turns out to be the developer tools and not the contents of the Scrimba course.

So, finally, if I understand you then vite is indeed the “magic sauce” and if I want to understand more fully then I should go look into it. Does that sound right?

Robert

Hi, no problem at all!
I think an understanding of vite is great but you probably don’t need a super deep dive - I expect a lot of devs don’t have deep knowledge of it unless they use it a lot!

Definitely good that you are learning how to run proejcts locally!

1 Like