Put TaskKit's React page on your computer with Vite: work on it with the dev server, which converts each file as the browser asks and updates the page on save, build it into a few files with TypeScript's check in front, and see why a wrong prop the dev server lets through stops the build.
TypeScript
React
Bundlers and dev servers (Vite). Read this lesson at .
Tested with TypeScript 7.x · Node.js LTS
In lesson A1.2 you wrote a React page, pressed Run, and it worked.
Now you want that page on your own computer. You save an index.html
with a <div id="root"> and a line that loads /src/main.tsx, put
your component in src/main.tsx, and double-click index.html. The browser
opens a blank page.
The browser could not use your files: it does not read TypeScript, it
does not know where react is, and it will not load code straight
from your disk. By the end of this lesson your page has Vite, a
tool that does all three for it. npm run dev (npm, the Node package
manager) shows the page and
changes it the moment you save a file, and npm run build checks the
types and packs the whole page into a few files any web host can
serve.
What the browser cannot read
This lesson puts lesson A1.2's React page on your computer. If you
skipped Part 1, read lesson A1.2 first; what else this lesson takes
from Part 1 is explained where it comes up.
Every browser has a console, a panel for the messages and errors of
the page you are on. In Chrome or Edge, open it with these keys:
⌘ Cmd+⌥ Option+J
Ctrl+Shift+J
Ctrl+Shift+J
On the blank page, the console's first line is this. It is one line
in the console, broken here to fit, and the list of schemes at its
end changes between browser versions (this is Chrome 158's):
In the browser's consoletext
Access to script at 'file:///src/main.tsx' from origin 'null' hasbeen blocked by CORS policy: Cross origin requests are only supportedfor protocol schemes: chrome, chrome-experimental-site-token-provider,chrome-extension, chrome-untrusted, data, http, https, isolated-app.
Access to script at 'file:///C:/src/main.tsx' from origin 'null' hasbeen blocked by CORS policy: Cross origin requests are only supportedfor protocol schemes: chrome, chrome-experimental-site-token-provider,chrome-extension, chrome-untrusted, data, http, https, isolated-app.
Access to script at 'file:///src/main.tsx' from origin 'null' hasbeen blocked by CORS policy: Cross origin requests are only supportedfor protocol schemes: chrome, chrome-experimental-site-token-provider,chrome-extension, chrome-untrusted, data, http, https, isolated-app.
CORS, short for cross-origin resource sharing, is the browser's set
of rules for which code a page may load. Your index.html loads
main.tsx with <script type="module">: a module script, one
that may import other files.
The browser loads modules only over http or https, short for
HyperText Transfer Protocol (the s is for secure): the way a
browser asks a server for a file. A file opened from your disk has the
address file:///, and the browser refuses. That is the first wall.
Behind it stand two more:
The browser runs only JavaScript. Your main.tsx holds types
and JSX tags (JSX, short for JavaScript XML: tags written inside
the code, lesson A1.2). Node strips the types out before it runs a
.ts file (Level 1's 9.4); a browser does not, and JSX is not
JavaScript at all.
The browser finds files only by their path.import { createRoot } from "react-dom/client" names a package. Node knows to look for it
in node_modules; a browser has never heard of that folder, and
says so:
Failed to resolve module specifier "react-dom/client". Relative references must start with either "/", "./", or "../".
And a fourth thing, not a wall but a cost: every import is one more
file the browser has to ask the server for, one after the other as it
reads them. Your page is a handful of files; with React and its parts,
the browser already asks for a dozen.
Two kinds of tool stand between your files and the browser:
A dev server, short for development server, is a small server
on your own computer. When the browser asks for a file, it converts
that one file into JavaScript the browser can run, and answers. When
you save a file, it tells the open page to fetch the new one.
A bundler reads your page's first file, follows every import
to the end, converts everything it finds, and writes the result as a
few files, ready to put on any web host.
Think of a book written in a language its reader does not speak. While
you are still writing it, a translator sits beside the reader and
translates each page as the reader turns to it; change a page, and the
translator hands over the new one at once.
When the book is finished, it is translated once, all of it, and
printed. The dev server is the translator beside the reader; the
bundler is the printing.
Vite (French for quick, said like "veet") is both: a dev server
for while you work, and a bundler for when you are done.
Start a page with Vite
Vite makes a new project for you, with every file the page needs. In a
terminal, go to your projects folder, the one that holds taskkit,
and run:
npm create, as in lesson A1.7, downloads a tool that makes projects
and runs it; here it is Vite's, and taskkit-web is the folder it
makes. Everything after the lone -- goes to Vite's tool instead of
to npm: --templatereact-ts asks for a page with React in
TypeScript, and --no-interactive makes it ask no questions. Without
it, it first asks a few questions, such as which linter you want and
whether to install everything now. This is create-vite 9.4, Vite's
tool, checked on 26 November 2026; its questions and the files below
change between versions. The end of its output:
Do as it says. npm install reads the new package.json and installs
React, React's types (@types/react, as in lesson A1.2), Node's
types, Vite with its React plugin (an add-on that lets Vite read
React's files), TypeScript and the linter into the new folder's own
node_modules:
Your time will differ. This is what Vite made; npm install added
node_modules and package-lock.json beside it:
taskkit-web/
public/files served as they are, such as the tab's icon
src/
assets/pictures the page imports
App.tsxthe component this lesson changes
App.cssthe component's styles
index.html is the page you would have double-clicked, with the same
<div id="root"> and <script type="module" src="/src/main.tsx">.
The difference is that now a server, Vite, hands the browser
/src/main.tsx when it asks. .oxlintrc.json
belongs to Oxlint, the linter this template picks unless you ask
for ESLint with --eslint, a linter as in lesson A2.2;
npm run lint runs it.
The dev server
This is what happens from the moment the browser asks for main.tsx to the
moment you save a change. The page you are about to open has a button that
counts its presses; the figure starts after three presses. hmr update is
Vite's message to the page that a file changed; HMR is short for hot module
replacement, explained below. Press Next step to follow it, or let it
play:
Browser
Vite
Yourfiles
1
Browser to Vite: GET/src/main.tsx
2
All 8 steps shown.Step 1 of 8: Browser → Vite — GET /src/main.tsxStep 2 of 8: Vite → Your files — read main.tsxStep 3 of 8: Vite — strip the types, turn JSX into callsStep 4 of 8: Vite → Browser — main.tsx as JavaScriptStep 5 of 8: Your files → Vite — App.tsx savedStep 6 of 8: Vite → Browser — hmr update /src/App.tsxStep 7 of 8: Browser → Vite — GET /src/App.tsxStep 8 of 8: Vite → Browser — the new App: Count is still 3
All 8 steps shown.
GET is the method of a request that asks for something, as in lesson
A1.3. Start the dev server:
Vite clears the terminal before it prints this, so the two lines npm
prints first, > taskkit-web@0.0.0 dev and > vite, are gone; your
time will differ. localhost is your own computer, as in lesson
A1.3, and 5173 is the port Vite listens on: a number that tells
apart the programs on one computer that wait for requests. The Network
line says the page is open to this computer only, and the last line
offers Vite's own shortcuts, which this lesson does not need.
Leave the terminal running and open
http://localhost:5173/ in your browser. The page has a heading, Get
started, and a button that says Count is 0. Press the button three
times: Count is 3.
Now change the page while it is open. In src/App.tsx, change the
heading and save the file:
By the time you look at the browser, the heading says TaskKit, and
the button still says Count is 3. The terminal has a new line;
your time will differ:
HMR, short for hot module replacement, is what the figure showed:
Vite tells the page which module changed, the page fetches only that
one and swaps it in, and everything else on the page stays as it was,
the count included. Nothing was reloaded.
Next, a file of your own. Create src/TaskCount.tsx with the
component from lesson A1.2:
Then use it in App.tsx: import it under the other imports at the
top, and put it under the heading:
In App.tsx, Vite's file, the new line follows its style: single
quotes, no semicolons. Your own TaskCount.tsx keeps TaskKit's. Save,
and Tasks: 3 appears under the heading.
You can ask Vite for a file yourself, the way the browser does. Open
http://localhost:5173/src/TaskCount.tsx in the browser. What comes
back is no longer your file. Its second to fourth lines:
The first and the last line are each one line, broken here to fit, and
the letters after ?v= will differ. TaskCountProps and the type are
gone, and <p>Tasks: {count}</p> has become a call to _jsxDEV, a
function of React's. To make that call work, Vite added an import of
React's code, and it names a path in node_modules, not a package's
name: the wall of package names is down. That is the JavaScript the browser
runs.
When you are done for now, stop the dev server in its terminal:
⌃ Control+C
Ctrl+C
Ctrl+C
Where TypeScript is in the project
The dev server strips your types; it never checks them. The checking
is TypeScript's, as it has been since Level 1, and Vite wrote its
settings for you. tsconfig.json holds almost nothing:
"files": [] means this file checks nothing itself. references
names two other settings files. TypeScript calls a settings file with
the files it checks a TypeScript project, and this folder holds
two of them. There are two because the code in this folder runs in two
places, and lib describes the place the code runs, as lesson A1.1
said. src/ runs in the browser; it is
checked by tsconfig.app.json:
Three of the lit lines come from Part 1, explained here again. Line 5
adds the DOM (Document Object Model: the page as objects your code
can reach), with document and every element type, as in A1.1 (A1.1
wrote dom in lower case; either works). Line 17 lets the check read
JSX, as in A1.2. Line 12, with "module": "esnext" on line 6, finds
files the way a bundler does, as in A1.4. Line 7 is new: vite/client
describes what Vite adds, such as importing a picture. App.tsx
writes import viteLogo from './assets/vite.svg', and that line
passes the check because of it.
The words between /* and */ are comments, which tsconfig.json
files allow, like // in your code. There is no strict line: since
TypeScript 6, strict is on unless a file turns it off, as lesson 9.4
said. include says which files this TypeScript project checks:
everything in src. The lines that lesson 9.4 taught,
allowImportingTsExtensions, verbatimModuleSyntax, noEmit and
erasableSyntaxOnly, mean what they meant there; noUnusedLocals and
noUnusedParameters refuse a name you never use; the rest you leave
as Vite wrote them.
The other TypeScript project, tsconfig.node.json, checks one file,
vite.config.ts, which Vite runs in Node, not in the browser: open
it, and its include names only that file. So its lib has no DOM,
and its types has node, as TaskKit's tsconfig.json does.
tsc -b checks them all (tsc is short for TypeScript compiler). -b is
short for build: TypeScript follows references and checks every TypeScript
project it names, each with its own settings. Level 3's Project references
and monorepos goes into the rest. Both TypeScript projects have "noEmit": true, so no JavaScript is written: only a small note in node_modules/.tmp
(line 3) that lets the next tsc -b skip what did not change.
Build the page
The dev server is for you, while you work. For the page's visitors,
you build it once. Look at package.json:
build runs two commands with &&, as in lesson A1.6: vite build
runs only if tsc -b ended with exit code 0 (the number a command
hands back when it ends: 0 means it worked), which here means every
type fits. Switch
between the scenarios, and press Next step to follow each, or let
it play:
src/: reachedmain.tsx, App.tsx, TaskCount.tsx
tsc -b: passes✓Do the types fit?
vite build: reachedStrips types, joins the files
dist/: reachedindex.html, .js, .css, pictures
npm run build: TypeScript checks every file, then Vite packs
them into a few
All 5 steps shown.Step 1 of 5: src/Step 2 of 5: tsc -bStep 3 of 5: tsc -b: passesStep 4 of 5: vite buildStep 5 of 5: dist/
All 5 steps shown.
src/: reachedmain.tsx, App.tsx, TaskCount.tsx
tsc -b: stops here✕Do the types fit?
vite build: never reachedStrips types, joins the files
dist/: never reachedindex.html, .js, .css, pictures
tsc -b stops hereTS2322: Type 'string' is not assignable to type 'number'.
npm run build: TypeScript checks every file, then Vite packs
them into a few
All 3 steps shown.Step 1 of 3: src/Step 2 of 3: tsc -bStep 3 of 3: tsc -b: stops here. TS2322: Type 'string' is not assignable to type 'number'.
All 3 steps shown.
Your types fit, so build it:
tsc -b printed nothing, which means it found nothing. Then Vite read
index.html, followed every import from main.tsx, through 21
modules (your files, React's, the styles and the pictures), and wrote
the page into a new folder, dist, short for distribution. The
pictures' and the CSS file's sizes and names match yours. The
JavaScript file's size and the letters in its name depend on the
versions of React and Vite npm installed, and your time will differ.
Your three .tsx files, React and its parts are now one JavaScript
file: one request instead of a dozen. The two CSS files (CSS,
Cascading Style Sheets, the files that set how the page looks) are
one CSS file. The pictures are copied as they are. kB is kilobytes;
the gzip column is the size each file travels at when the server
compresses it with gzip, as most servers do.
The letters in each name, such as DdKH_qJb, are a hash: a short
code Vite works out from the file's content. Change one word in
App.tsx, build again, and the JavaScript file gets a new name. A
browser keeps the files it has loaded, to save time on the next
visit. A new name makes it fetch the new file.
dist is everything the page needs, and nothing that runs on your
computer. Any service that serves files can host it. Before you put
it anywhere, look at it the way a visitor will:
http://localhost:4173/ serves dist, exactly as built: no
conversion, no updates when you save. Stop it with the same keys as the
dev server. .gitignore already names dist, so the build never goes
into Git: it is made again from src whenever it is needed.
Vite is not the only bundler, and a project you join may use another.
Its settings file says which:
The project has
It uses
vite.config.ts
Vite, built on Rolldown since version 8
webpack.config.js
webpack, the bundler of many older projects
rollup.config.js
Rollup, which Vite used before Rolldown
next.config.ts
Next.js, a React framework with its own bundler
The ideas are the same in all of them: a server that converts files
while you work, and a build that packs them for the browser.
Predict before you run
The dev server is running, and you have pressed the button three
times: it says Count is 3. Now you change the tab's title in
index.html and save.
Predict
What does the button say once the page has updated?
The common mistake: trusting the dev server
The page in the dev server is not a check.
Common mistake
A wrong prop the dev server lets through
You start the dev server again and change one prop in App.tsx,
writing the number in quotes:
The page still says Tasks: 3: as lesson A1.2 showed, a string "3"
looks the same on the page as the number 3. The terminal prints its
hmr update line and nothing else, and the browser's console shows no
error or warning. Then you build:
Two long lines are broken here to fit; in your terminal each is one
line. The error names line 21 and the prop, and the second part says
where the type it expected was written: count: number, line 2 of
TaskCount.tsx. IntrinsicAttributes holds the props React gives
every component, such as key; & joins them to yours. tsc -b
ended with 1, so && never ran vite build, and dist was not
touched.
error TS2322: Type 'string' is not assignable to type 'number'.
The fix
Pass a number, in braces, as in lesson A1.2:
npm run build passes again. VS Code (Visual Studio Code, your
editor) draws a red line under count
the moment you type the quotes, because the editor runs TypeScript's
check too; the browser never does.
A wrong type that happens to look right on the page is the one the
dev server will never show you. So keep tsc -b && at the front of
the build, never call vite build on its own, and run
npm run build before you push. Run by itself, npx vite build packs
this very page and reports no error.
Pass all four tasks to complete the lesson with practice. Reach the end without them and it counts as read only.
Exercises
This lesson's page cannot run Vite or npm, so the commands are written
as console.log lines, and one exercise holds the scripts part of a
package.json as a TypeScript object.
Recap
Recap · 3 questions
Check yourself
What does the dev server do when asked for main.tsx?
Check yourself
Why did the page show Tasks: 3 with a wrong prop?
Check yourself
What does npm run preview serve?
0 of 0 answered.
A cheat sheet to keep
Cheat sheet
Bundlers and dev servers (Vite)
What things are
Word
What it means
Console
The browser's panel for a page's messages and errors
Module script
<script type="module">: a script that imports
Dev server
Converts each file when the browser asks for it
Bundler
Follows every import and writes a few files
Vite
A dev server and a bundler in one
HMR
Swaps a saved module into the open page
dist
The built page, ready for any web host
Hash
Letters in a file name that change with its content
Commands and settings
Write
To
npm create vite@latest
Make a project: its folder, then the options
-- --templatereact-ts
Ask for React in TypeScript
--no-interactive
Make it ask no questions
npm run dev
Serve the page at localhost:5173
npm run build
tsc -b, then vite build into dist
npm run preview
Serve dist at localhost:4173
tsc -b
Check every TypeScript project in references
"types": ["vite/client"]
Let the check read Vite's imports
"moduleResolution": "bundler"
Find files the way a bundler does
Rules
Where to go next
You can now start a TypeScript page with Vite, work on it with the dev
server, build it into dist, and say why a page that works in the dev
server may still fail TypeScript's check.
Next is CI: running your checks on every pull request. CI, short
for continuous integration, is a service that runs your checks,
npm run build among them, on every pull request, so a wrong prop is
stopped before anyone merges it.
Before you move on, run npm run build, then npm run preview, and
open http://localhost:4173/. Change the heading again, build again,
and find the new name of the JavaScript file in dist/assets.
Vite converts a file only when the browser asks for it, and
tells the page when you save one
dist
Rule
What it means
The page is not a check
The dev server strips types, never reads them
tsc -b && stays in build
A wrong type stops the build
Two TypeScript projects
src for the browser, vite.config.ts for Node
dist stays out of Git
It is made again from src
Exercise · Read the code
A picture that did not change
A visitor opened your page yesterday, so their browser keeps
dist/assets/hero-CLDdwZDr.png. Today you change one word in
App.tsx, build again and put the new dist online. When the visitor
comes back, does their browser need to download the picture again?
Exercise · Read the code
The settings for vite.config.ts
You add a line to vite.config.ts. When npm run build runs
tsc -b, which settings file is that line checked by?
The end of the outputtext
└ Done. Now run: cd taskkit-web npm install npm run dev
The first line of npm's outputtext
added 28 packages, and audited 29 packages in 12s
Outputtext
VITE v8.3.5 ready in 555 ms ➜ Local: http://localhost:5173/ ➜ Network: use --host to expose ➜ press h + enter to show help
> taskkit-web@0.0.0 preview> vite preview ➜ Local: http://localhost:4173/ ➜ Network: use --host to expose ➜ press h + enter to show help
Outputtext
> taskkit-web@0.0.0 build> tsc -b && vite buildsrc/App.tsx:21:22 - error TS2322: Type 'string' is not assignable totype 'number'.21 <TaskCount count="3" /> ~~~~~ src/TaskCount.tsx:2:3 - The expected type comes from property 'count' which is declared here on type 'IntrinsicAttributes & TaskCountProps' 2 count: number; ~~~~~Found 1 error in src/App.tsx:21
bash
cd ~/projectsnpm create vite@latest taskkit-web -- --template react-ts --no-interactive
You have just run npm create and have a new taskkit-web. This
program prints the commands from there to looking at the built page,
but in an order that would not work. Change the order of the lines,
without changing any line itself, so the commands work from top to
bottom: install, work on the page, build it, then look at the build.
Loading the editor…
Exercise · Fix the error
Put the check back in the build
A teammate found the build slow and shortened it. This is the
scripts part of their package.json, as a TypeScript object that
prints the build command. With it, a wrong prop reaches dist. Change
the one value that is wrong, so the build checks the types first and
packs the page only if they fit.