A package for npm: build TaskKit, describe it and try it
Build TaskKit into JavaScript with a second tsconfig, say in package.json what the package is and what it holds, and install the tarball the way someone else will, before the next lesson publishes it.
TypeScript
npm
A package for npm: build TaskKit, describe it and try it. Read this lesson at .
Tested with TypeScript 7.x · Node.js LTS
Your friend has run TaskKit from her clone of your repository since
lesson 15.3: cd into that folder, npm start every time, and
git pull whenever you change something. One evening she writes: "I
type node and npm in any folder and they just work. Why does
TaskKit only work in one folder, and only after a pull?"
She is right, and the answer is npm (Node package manager). Node and
npm reached her computer as installed programs, and so do thousands of
tools published as packages on the npm registry, the one lesson 9.2
installed boxen from. In this lesson TaskKit becomes a package. You
build it into JavaScript, choose what its package holds, and install
the package on your own computer exactly as she will, so that the next
lesson can publish it with nothing left to fix.
From your folder to her computer
Lesson 9.2 used npm from one side: npm install boxen downloaded a
package from the npm registry, the public library of packages
behind npmjs.com. Publishing is the other side. A package is a
folder with a package.json, packed into one compressed file, a
tarball, that ends in .tgz. npm publish sends the tarball to
the registry, and from then on anyone's npm install can download it
and unpack it into a node_modules folder.
Every package on the registry needs a name nobody else has, and
taskkit is taken: npm view taskkit, which prints a package's
details from the registry, shows someone else's taskkit@3.2.1 (on
26 November 2026). So
TaskKit goes out under a scope, @ana/, your npm username with an
@ in front. Only you can publish names that start with your scope,
so @ana/taskkit is yours the day you make the account. In this
course ana stands for your own username, as it stands for your
account name on your computer.
-g, short for global, installs a package into a node_modules
folder that belongs to the whole computer rather than to one project,
and puts its command in a folder on the PATH. The command comes from
bin, the field of package.json that pairs a command's name with
the file it runs. That is how taskkit will work in any folder on her
laptop.
Five steps take TaskKit from your folder to her computer, and two
things can go wrong on the way. One stops on your side, at npm publish, and is the next lesson's. The other passes everything you
run and fails only when she types taskkit, which is why this lesson
tries the package first. It takes the first two steps, the build and
the tarball, and installs the tarball as she will. Switch between the
three cases, and press Next step to follow each, or let it play:
npm run build: reachedtsc writes dist/*.js
npm pack: reacheddist, README, package.json
npm publish: passes✓Is this version new?
npm install -g: reachedOn her computer, into node_modules
taskkit: passes✓Node runs the file bin names
TaskKit's way to another computer; the first stage that
fails stops the rest
All 7 steps shown.Step 1 of 7: npm run buildStep 2 of 7: npm packStep 3 of 7: npm publishStep 4 of 7: npm publish: passesStep 5 of 7: npm install -gStep 6 of 7: taskkitStep 7 of 7: taskkit: passes
All 7 steps shown.
npm run build: reachedtsc writes dist/*.js
npm pack: reacheddist, README, package.json
npm publish: passes✓Is this version new?
npm install -g: reachedOn her computer, into node_modules
taskkit: stops here✕Node runs the file bin names
taskkit stops hereStripping types is currently unsupported for files under
node_modules
TaskKit's way to another computer; the first stage that
fails stops the rest
All 7 steps shown.Step 1 of 7: npm run buildStep 2 of 7: npm packStep 3 of 7: npm publishStep 4 of 7: npm publish: passesStep 5 of 7: npm install -gStep 6 of 7: taskkitStep 7 of 7: taskkit: stops here. Stripping types is currently unsupported for files under
node_modules
All 7 steps shown.
npm run build: reachedtsc writes dist/*.js
npm pack: reacheddist, README, package.json
npm publish: stops here✕Is this version new?
npm install -g: never reachedOn her computer, into node_modules
taskkit: never reachedNode runs the file bin names
npm publish stops hereYou cannot publish over the previously published versions:
1.0.0.
TaskKit's way to another computer; the first stage that
fails stops the rest
All 4 steps shown.Step 1 of 4: npm run buildStep 2 of 4: npm packStep 3 of 4: npm publishStep 4 of 4: npm publish: stops here. You cannot publish over the previously published versions:
1.0.0.
All 4 steps shown.
Why the package holds JavaScript
On your computer, npm start runs node index.ts, and Node strips
the types as it reads the file. It does that only for your own files.
A file under node_modules is someone else's package, and there Node
refuses: a package is expected to arrive as JavaScript that every
program can run as it is, with no types to strip and no
tsconfig.json of yours to read. So TaskKit's package holds
JavaScript, and TypeScript writes it.
Until now tsc (the TypeScript compiler) has only checked: TaskKit's
tsconfig.json says "noEmit": true, write nothing (lesson 9.4).
It has to stay that way: npm run check checks the tests too and must
never write files. So the build gets a second settings file, which
keeps every setting of the first, changes three, and leaves the tests
out. In taskkit, on a new branch (-c for create):
Make tsconfig.build.json beside tsconfig.json:
extends takes every setting from tsconfig.json, and the lines
under it change only what differs. "noEmit": false lets tsc write
files, and outDir says where: a folder dist, short for
distribution, as Vite's in lesson A2.4. exclude leaves the tests
out, since nobody who installs TaskKit runs them, and leaves dist
out, so a build never reads the last build.
rewriteRelativeImportExtensions is the line people miss. TaskKit
imports its own files as ./tasks.ts (lesson 9.1). In dist there is
only tasks.js, so the import of ./tasks.ts has to become
./tasks.js, and the same for every file; this setting rewrites them.
Without it, tsc reports an error:
allowImportingTsExtensions comes from tsconfig.json, through
extends: it lets TaskKit write .ts in its imports, and is allowed
only when nothing is written or the imports are rewritten. tsc still
writes the files when it reports this, and every one of them imports a
.ts file that is not in dist, so read the output of every build.
Add a script for the build in package.json, beside check:
-p names the settings file, as npx tsc -p server did in lesson
A1.4. Run it:
Nothing more is printed, so nothing was wrong, and dist now holds
one .js file for each .ts file except the tests. Here is one of
them, colors.ts, and what the build wrote from it:
It is the same program. The types are gone: status has no Status,
the function no : string, and the import type line is gone whole,
since it brought in nothing but a type. tsc writes four spaces where
Biome writes two, which does not matter in a file nobody edits.
dist is made again from the .ts files by every build, so it stays
out of Git, as Vite's did in lesson A2.4. Add one line to
.gitignore:
That line matters to Biome too: it skips what .gitignore names, and
without it npx biome format . would complain about the files in
dist.
Two things an installed tool needs
Run in your folder, TaskKit is fine. Installed, two of its habits
break.
The first is where it keeps the list. store.ts says const file = "tasks.json", a name with no folder, so it is read and written in the working
directory, whatever folder the terminal is in: installed, taskkit add in
Downloads would start a new list there. Lesson A1.6 kept the list beside the
code with import.meta.dirname, which works for a link, but not for an
installed package:
Beside the code
Gone after an update
In the package's own folder, under node_modules, which the next
version replaces whole.
In your home folder
Stays through every update
.taskkit.json in your home folder, which npm never touches.
npm replaces the package's folder on every update
So the list moves to your home folder. In store.ts, put these lines
in place of the file line; if you made lesson A1.6's change,
store.ts already imports join, so keep one join import and
replace the import.meta.dirname line:
homedir() from node:os (Node's module about the operating system)
gives your home folder: /Users/ana on a
Mac, C:\Users\ana on Windows, /home/ana on Linux. join from
node:path puts a folder and a file name together into one path, with
the right slashes for your system. The dot at the start of
.taskkit.json hides the file from plain ls and the file manager on
macOS and Linux, as with .github in lesson A2.5; Windows shows it.
npm start uses the new place too, so move the list you have there
once:
mv, short for move, moves a file and can rename it on the way, and
prints nothing when it works. It works in PowerShell too, and ~ is
your home folder everywhere. If it says there is no tasks.json, you
have no list yet, and nothing needs moving.
The second habit is the version. index.ts says
const version = "1.0", and taskkit --version prints that, whatever
package.json says. Make it read package.json instead:
The first line imports a JSON (JavaScript Object Notation) file, the
format package.json is written in: with { type: "json" } tells
Node to read it as data rather than as code, and TypeScript then knows
every field's type, version a string. Put the import with the
others at the top of index.ts, and change the const version line
where it is. The build copies package.json into dist beside
index.js, so the import finds it there too.
Say what the package is
package.json is also the package's label. Add these fields at its
top, above devDependencies; if lesson A1.6 gave it name and bin,
change those two rather than adding them again:
name is the package's name, with your scope.
version is the first version, 1.0.0. The next lesson,
Publishing a package to npm, says what each number means.
bin pairs the command taskkit with the built dist/index.js,
never index.ts.
files lists what goes into the package; the end of this section
shows why.
publishConfig holds settings for npm publish. npm's
documentation says a package with a scope is published as private
unless it says otherwise, and on 26 November 2026 private packages
needed a paid account (plans change), so "access": "public".
The list in files takes three lines because Biome lays an array in
package.json out that way: written on one line, npx biome format .
fails, and so do the checks on the pull request.
The command runs the file itself, so dist/index.js has to say which
program reads it. If you did lesson A1.6, index.ts already starts
with this line, the shebang; if not, add it as line 1:
It is #! and the program to start, here "the node your PATH
finds". tsc copies the line into dist/index.js. Windows does not
read it; npm does, and writes small files that start Node there.
One more script beside build:
npm runs a script named prepack by itself, before every npm pack
and every npm publish. && runs the build only if the check passed
(lesson A1.6), so a package with a type error is never made, and every
package is built from your code as it is now, never from an older
dist.
The README is the package's page on npmjs.com, so tell people how to
install it there. Its Install and Use parts become:
Keep the three - lines under Use that say what each command does.
What does files save you from? Ask npm what the package would hold,
without making it: npm pack --dry-run runs prepack first, then
lists every file.
Bad — no files field, so npm packs
nearly everything in the folder: sources, tests and settings as well
as dist.
Good — files names dist, so the
package holds the built files and what npm always adds.
Without files, the package holds 24 more files nobody who installs
TaskKit runs, the .ts sources, the tests, .github and the settings
(more still if you did Part 1, whose folders are in Git since lesson
A2.1), and every install downloads them. README.md, package.json
and a LICENSE file if there is one are always packed, whatever
files says, and so is the file bin names. Your sizes may differ by
a few bytes.
Run the checks before you go on, the formatter's too:
All four pass as before: ℹ pass 19 at the end.
Try it as she will
npm pack makes the real tarball, the very file npm publish would
send:
The last line is the file's name: the scope and the name joined with
-, then the version. Install it the way she will install TaskKit
from the registry, with -g, but from the file:
The 19 are TaskKit and the packages it depends on. devDependencies
are not among them: TypeScript and Biome help only you.
EACCES is short for error: access. npm installs global packages
into a folder that, with the installer from nodejs.org, belongs to the
system. As with npm link in lesson A1.6, put sudo in front, sudo npm install -g ./ana-taskkit-1.0.0.tgz, and type your Mac's password
(it shows nothing as you type). The same goes for every
npm install -g and npm uninstall -g in this lesson.
After lesson A1.6: npm install -g says EEXIST
EEXIST is short for error: exists. npm link in lesson A1.6 made
a command taskkit for the package then named taskkit, and npm will
not write a second command over it: the error names your taskkit
command and says Remove the existing file and try again. Remove the
old link with npm uninstall -g taskkit, then run the install again.
Now go somewhere that is not the project, and use it:
Node ran dist/index.js, plain JavaScript, from under node_modules.
The frame says 1.0.0, the version from package.json, and the list
is in .taskkit.json in your home folder, not in Downloads. This
output starts from an empty list; if you moved one, your earlier tasks
are listed too, and the counts differ.
Take the test install back out, go back to taskkit, and delete the
tarball: rm, short for remove, deletes a file, in PowerShell too.
The time differs from run to run.
Predict before you run
Predict
What file does npm pack make for this package.json?
The common mistake: bin names a .ts file
npm start runs index.ts, so bin is easy to point there too, and
lesson A1.6 did, for npm link, which points at your own folder,
where Node strips types. Add the build and files but leave that one
line, and nothing on your side notices.
Common mistake
Packing with bin still set to index.ts
npm run check passes, the build writes dist, npm pack packs
index.ts because bin names it, and npm install -g installs it.
Then taskkit add "Call the bank" stops at once: the command runs
index.ts from under node_modules, where Node will not strip types.
Error [ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING]: Stripping types is currently unsupported for files under node_modules
The fix
Point bin at the file the build writes:
Pack it again, install the new tarball, and taskkit runs.
The error comes from her computer, not yours, and a package already
published cannot be changed, only replaced by a new version (npm's
rule, which the next lesson shows). That is
why you install the tarball yourself before the first publish, and
whenever bin or files changes: it is the one step on your side
that runs the package the way she will.
Pass all three tasks to complete the lesson with practice. Reach the end without them and it counts as read only.
Exercises
This page cannot pack or install a package, so one exercise writes
package.json as a TypeScript object, and two ask what npm does with
files and folders.
Recap
Recap · 3 questions
Check yourself
Why does TaskKit's package hold JavaScript?
Check yourself
Why does the build rewrite the .ts in each import?
Check yourself
Why install the tarball before you publish?
0 of 0 answered.
A cheat sheet to keep
Cheat sheet
A package for npm: build it, describe it, try it
What things are
Word
What it means
Package
A folder with a package.json, packed into one file
Tarball
That file: ana-taskkit-1.0.0.tgz
Registry
Where packages are published and installed from
Scope
@ana/: your username; only you publish under it
Global install
-g: for the whole computer, its command on the PATH
The build and package.json
Write
To
"extends": "./tsconfig.json"
Take every setting, change a few
"noEmit": false
Let tsc write files
"outDir": "dist"
Write them into dist
rewriteRelativeImportExtensions
Turn ./tasks.ts into ./tasks.js
"build": "tsc -p tsconfig.build.json"
Build with those settings
"bin": { "taskkit": "dist/index.js" }
Run the built file
"files": ["dist"]
Pack only the build; Biome puts it on three lines
"publishConfig"
"access": "public" for a scoped package
"prepack"
Run before every pack and publish
with { type: "json" }
Import a JSON file, such as package.json
join(homedir(), ".taskkit.json")
A file in your home folder
Where to go next
You can now build TaskKit into JavaScript, choose what its package
holds, and try it the way someone else will install it.
Next is Publishing a package to npm, which publishes the package
to the registry, so that npm install -g @ana/taskkit is all she
types, and releases new versions with the right number. Leave this
lesson's work on the publish branch as it is: the next lesson
commits it.
Before you move on, run npm pack --dry-run once more and read the
list: every file in it should be one she needs, and none of the .ts
sources or tests should be there.
Commands
Write
To
npm pack --dry-run
List what the package would hold
npm pack
Make the tarball
npm install -g ./ana-taskkit-1.0.0.tgz
Install it as she will
npm uninstall -g @ana/taskkit
Take a global install back out
Rules
Rule
What it means
No .ts under node_modules
Ship what tsc writes
dist stays out of Git
Every build makes it again
Try the tarball first
The one step that runs it as she will
Keep data in the home folder
npm replaces the package's folder
Exercise · Read the code
What the tarball holds
TaskKit's package.json has "files": ["dist"], bin names
dist/index.js, and the folder holds README.md. Which files does
npm pack put in the tarball?
Exercise · Read the code
A list that disappeared
Your friend's own tool, @her/notes, keeps its notes in
join(import.meta.dirname, "notes.json"), beside its code. She
installs version 1.0.1 over 1.0.0 with npm install -g @her/notes,
and every note is gone. Why?
Outputtext
tsconfig.build.json(3,3): error TS5096: Option 'allowImportingTsExtensions' can only be used when one of 'noEmit', 'emitDeclarationOnly', or 'rewriteRelativeImportExtensions' is set.
npm notice total files: 17npm noticeana-taskkit-1.0.0.tgz
Outputtext
added 19 packages in 2s15 packages are looking for funding run `npm fund` for details
Outputtext
┌ TaskKit 1.0.0 ─────────────┐│Your tasks, in your terminal│└────────────────────────────┘Added: Call the bank1 task added, room for 4 moreList 20% fullYour list, by due date:#1 [todo] Call the bank, due: not set
import chalk from "chalk";import type { Status } from "./tasks.ts";export function paintStatus(status: Status): string { if (status === "done") { return chalk.green(status); } if (status === "doing") { return chalk.blue(status); } return chalk.yellow(status);}
dist/colors.jsjs
import chalk from "chalk";export function paintStatus(status) { if (status === "done") { return chalk.green(status); } if (status === "doing") { return chalk.blue(status); } return chalk.yellow(status);}
store.ts (part)ts
import { homedir } from "node:os";import { join } from "node:path";const file = join(homedir(), ".taskkit.json");
bash
mv tasks.json ~/.taskkit.json
index.ts (part)ts
import packageJson from "./package.json" with { type: "json" };const version = packageJson.version;
TaskKit's package.json is written here as a TypeScript object. Its
command still runs the .ts file, and it packs every file. Make
bin run the built file, and add the field that packs only dist.
Loading the editor…
README.md (part)markdown
## InstallYou need Node.js 24 or newer:```bashnpm install -g @ana/taskkit```## Use```bashtaskkit add "buy milk"taskkit add --due 2026-12-25 "go to the bank"taskkit remind "call Mom"taskkit help```