Skip to main content
Code you use from several places does not need a relative path. Put it in lib/ and import it by name.

Rules

  • A folder under lib/ is a library when it contains lib.ts, lib.tsx, lib.js or lib.jsx.
  • Its name is whatever that file exports as libId. Without one, the folder name is used, so lib/helpers/lib.ts is import x from 'helpers'.
  • libId is read from your source without running it, so it must be a plain string literal.
  • Names are letters, digits, _ and -.
  • Other files in the library are reachable by subpath: greeter/shout, greeter/nested/thing.
  • Two libraries cannot share a name, and a lib/ folder without an entry file is an error. Both are reported when the expansion loads, naming the folder.

What they are, and are not

A library is ordinary code in your expansion: same runtime, same permissions, compiled and cached the same way, hot-reloaded with everything else. The only thing that changes is how you import it.
They are per-expansion. Sharing a library between expansions is the NMCrate library system, which is not available yet; dependencies in meta.json must stay empty. The folder shape here is the shape that system will install into, so code written against a local library will move across unchanged.

Editor support

The app writes .ldstudio/tsconfig.libs.json with a path mapping per library, and your tsconfig.json extends it. Because those are mappings rather than declarations, you get the library’s real types, its default export and go-to-definition. Add or rename a library and the file is rewritten the next time the app loads the expansion.