DEV Community

scl
scl

Posted on • Edited on

Publishing my Typescript package to npm

(Managed to get one working here: https://www.npmjs.com/package/api-gateway-direct-dynamodb)

Documenting the steps to publish a Typescript project to npm.

Check that tsconfig.json is emitting declaration files:

    "declaration": true, 
    "outDir": "./dist",
Enter fullscreen mode Exit fullscreen mode

Compiles all Typescript source files and generates type declarations files:

rm -rf ./dist
npx tsc
Enter fullscreen mode Exit fullscreen mode

Check that ./dist contains the compiled .js and .d.ts files.

Edit package.json to inform users' compilers on where to find the type declarations:

  "main": "dist/index.js",
  "types": "dist/index.d.ts",
Enter fullscreen mode Exit fullscreen mode

This next step is optional, which is to test the library locally before publishing. Create another empty project and try to installing the library:

npm install path/to/my-package
Enter fullscreen mode Exit fullscreen mode

Finally, publish the library:

npm publish
Enter fullscreen mode Exit fullscreen mode

(For subsequent republishing, we would also need to increment the version number in package.json.

Ref: https://medium.com/cameron-nokes/the-30-second-guide-to-publishing-a-typescript-package-to-npm-89d93ff7bccd

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more