This template demonstrates a small native ESM library. Native ESM uses JavaScript import and export statements.
After you create a repository from this template, replace this document with usage instructions for the derived library.
Use Node.js 26 or later to run the sample and validate this repository. Use an ESM project to import the sample API.
- Create a repository from this template.
- Set the package name, description, keywords, repository URL, homepage, issue URL, author, and license in
package.json. - Set the package version to the first version for the derived library.
- Set
privatetotruewhen the package must not publish to npm. - Set
privatetofalseand set the correctpublishConfig.accessvalue when you publish to npm. - Replace the sample source, type declarations, examples, tests, and documentation.
- Update
main,types,exports, andfilesto match the derived library. - Remove or adapt
.github/workflows/npm.yamlwhen the derived library does not publish to npm. - Run the validation commands before you share or publish the derived library.
The package name @eliware/library-template is not available from npm. Do not use it as an installable package name.
Run this command from the repository root:
node examples/basic.mjsThe command prints:
Hello, Eli!
The example calls createGreeting with the name Eli.
Read the API reference for details about this function.
Publish the derived package before you install it from npm.
npm install @your-scope/your-libraryReplace @your-scope/your-library with the package name in the derived library's package.json.
Import documented exports from the package root:
import { createGreeting } from "@your-scope/your-library";
console.log(createGreeting("Eli"));This example works after the derived package exports createGreeting from its package root.
Change the example when the derived library uses a different API.
Run these commands from the repository root:
npm ci
npm test
npm run typecheck
npm run packnpm ci installs the locked dependencies.
npm test runs aggregate repository checks.
npm run typecheck checks the TypeScript declaration.
npm run pack checks the files that npm includes in a package.
The npm workflow starts when you push a tag that matches vMAJOR.MINOR.PATCH.
The workflow runs npm test and checks that the tag matches the version in package.json.
After those checks pass, the workflow runs npm publish --provenance.
Configure npm trusted publishing for the derived GitHub repository and workflow before you push a release tag. Complete the approved release steps before you publish a tag. Remove or adapt the npm workflow when the derived library does not publish to npm.
If npm reports E404, check the package name, registry, publication status, and access settings.
The template package is not published, so install a derived package only after its owner publishes it.
If Node.js cannot resolve an import, check the installed package name and the exports field.
Read the API reference to confirm the package root export.