Installing from Folio's registry
Folio's packages are published privately to Folio's own npm registry, https://folio.nextgen-softwares.com/npm/, under the @nextgensoftwares scope (@nextgensoftwares/folio-model, @nextgensoftwares/folio-react, @nextgensoftwares/folio-reader, ...). Installing needs a token from the Folio maintainers. Every package ships ESM, CJS, type declarations, LICENSE and NOTICE. Each package has its own version: a release publishes only the packages that changed.
Versions up to 0.108.7 were published to GitHub Packages. Lockfiles that still resolve there keep working while those versions stay up; reinstall the Folio packages to move a lockfile to the new registry (the tarballs, and their integrity hashes, are the same).
1. Point the scope at the registry
Add an .npmrc next to your package.json (commit it; it holds no secret):
@nextgensoftwares:registry=https://folio.nextgen-softwares.com/npm/
//folio.nextgen-softwares.com/npm/:_authToken=${FOLIO_NPM_TOKEN}Only the @nextgensoftwares scope goes to Folio's registry; everything else still comes from npmjs. npm, pnpm and Yarn (v1, or v2+ with npmScopes in .yarnrc.yml) read this file.
2. Authenticate with your token
Each consumer gets its own read-only token. Export it in your shell profile (never commit it):
export FOLIO_NPM_TOKEN=... # from the Folio maintainers
pnpm add @nextgensoftwares/folio-model @nextgensoftwares/folio-layout @nextgensoftwares/folio-fontsnpm whoami --registry https://folio.nextgen-softwares.com/npm/ shows which user the token belongs to.
3. CI
Store the token as a CI secret and pass it to the install step:
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
env:
FOLIO_NPM_TOKEN: ${{ secrets.FOLIO_NPM_TOKEN }}4. Docker builds: BuildKit secrets, never a baked token
Mount the .npmrc (or the token) as a BuildKit secret only for the install step, so it never lands in an image layer or the build cache:
# syntax=docker/dockerfile:1
FROM node:22-alpine AS deps
WORKDIR /app
RUN corepack enable
COPY package.json pnpm-lock.yaml ./
RUN --mount=type=secret,id=npmrc,target=/root/.npmrc \
pnpm install --frozen-lockfileBuild with a user-level .npmrc that contains the real token:
printf '@nextgensoftwares:registry=https://folio.nextgen-softwares.com/npm/\n//folio.nextgen-softwares.com/npm/:_authToken=%s\n' "$FOLIO_NPM_TOKEN" > /tmp/npmrc
docker build --secret id=npmrc,src=/tmp/npmrc -t my-app .
rm /tmp/npmrcIn GitHub Actions, docker/build-push-action takes the same secret: secret-files: npmrc=/tmp/npmrc (or secrets: npmrc=...). Do not use ARG FOLIO_NPM_TOKEN or COPY .npmrc with a token in it: build args and copied files are visible in the image history. With Compose, declare it under build.secrets and a top-level secrets: npmrc: file: ....
5. Next.js (App Router)
- No
transpilePackagesneeded. The packages are compiled JavaScript (ES2022) withexportsmaps. Add them totranspilePackagesonly if you target older browsers than ES2022. - Client only for the editor and reader.
@nextgensoftwares/folio-react,@nextgensoftwares/folio-editorand@nextgensoftwares/folio-reader/reactuse the DOM: import them from'use client'components, and load the editor withnext/dynamic(() => import('./Editor'), { ssr: false })so it never renders on the server. - Fonts.
FontEngine(HarfBuzz WebAssembly) loads lazily in the browser. Serve the font files you lay out with (e.g. frompublic/fonts/) and register the same bytes withdocument.fonts(see Fonts). - No
resolveAliasformodule. HarfBuzz's own loader contains a Node-onlyimport("module")(plusrequire("fs")) that client bundlers try to resolve.@nextgensoftwares/folio-fontshas abrowserexport condition (0.3.0+) whose copy of that loader has the Node branch removed, so Turbopack and webpack client bundles build as is; server code keeps the Node entry. On 0.2.x, alias it away:turbopack: { resolveAlias: { module: { browser: './empty-module.ts' } } }innext.config.ts(an empty module) or upgrade. - Styles. Render
<FolioStyles />once, or import@nextgensoftwares/folio-react/styles.cssin a layout. - Workers. The reader's worker layout uses
new Worker(new URL('./layout.worker.ts', import.meta.url), { type: 'module' }), which both Turbopack and webpack bundle.
6. NestJS / Node services
Server-side packages (model, layout, fonts, docx, export-pdf, export-docx, sync, server-node, every plugin's /schema entry) work from both CommonJS (NestJS's default output) and ESM, on Node 20+:
import { readFileSync } from 'node:fs';
import { FontEngine } from '@nextgensoftwares/folio-fonts';
import { layoutDocument } from '@nextgensoftwares/folio-layout';
import { exportPdf } from '@nextgensoftwares/folio-export-pdf';
const geist = readFileSync('fonts/Geist-Variable.ttf');
const fonts = await FontEngine.create({ fallback: [] });
fonts.addFont({ family: 'Geist', data: geist });
const pdf = await exportPdf(layoutDocument(doc, { measurer: fonts }), { fonts: () => geist, shaper: fonts });@nextgensoftwares/folio-render-node needs the native @napi-rs/canvas; with Next.js route handlers, list it in serverExternalPackages. Never import a plugin's root entry on the server just for its schema: use @nextgensoftwares/folio-plugin-<name>/schema, which has no React or DOM. Likewise @nextgensoftwares/folio-sync/server (sync without the client's editor assembly), @nextgensoftwares/folio-pm-schema (toProseMirrorSchema alone) and @nextgensoftwares/folio-layers-core (drawings without the editor).
Since 0.5, installing any Node-side package (model, layout, fonts, import, import-formats, docx, pptx, export-docx, export-pdf, charts, slides, layers-core, pm-schema, sync, server-node) puts no React, React DOM, folio-react, folio-editor, folio-plugin-layers or ProseMirror view in node_modules. CI checks it twice: tools/check-node-entries.mjs (import graphs and dependency trees) and tools/check-node-installs.mjs (pnpm pack every package, then a clean install of each Node-side one). Client packages that need the editor (folio-sync's main entry, folio-plugin-collab, folio-plugin-comments) take it as an optional peer: your app lists @nextgensoftwares/folio-editor (see Upgrading to 0.5).
Upgrading
After 0.108.8 each package has its own version: a fix in folio-layout publishes folio-layout (and the packages that changed with it), not every package. Upgrade them together to their latest versions, e.g. pnpm up "@nextgensoftwares/folio-*" --latest. Pre-1.0, a minor bump may break APIs; read the package changelogs.
Folio packages depend on each other with caret ranges (^0.108.8: any later patch), so one copy of each serves them all. A lockfile can still keep nested copies of an old version (folio-model, folio-layout, folio-editor…). Then two copies of a package load, and things like instanceof checks and shared registries break. After an upgrade:
pnpm why @nextgensoftwares/folio-model # every path should show one versionIf you see two versions, remove every @nextgensoftwares/ entry from the lockfile (or run pnpm up "@nextgensoftwares/*" --latest and pnpm dedupe) and install again. You should end up with a single set.
New releases can add UI strings (for example, 0.32 added seven to BOOK_STRINGS for chapter reordering). If your app translates Folio's strings through its own catalog, compare the exported string tables (BOOK_STRINGS and the others) with your catalog after an upgrade, so new labels don't show up untranslated or as raw keys.