Using npm Packages
Pure resolves npm packages at compile time, not at runtime. When you import a package, Pure includes its code in the compiled binary. You do not need node_modules present on the machine running the binary.
How package resolution works
Section titled “How package resolution works”- Run
npm installin your project directory as usual. This populatesnode_modules. - Run
pure build. Pure readsnode_modulesand includes all imported packages in the binary. - The compiled binary contains the package code —
node_modulesis not needed at runtime.
You can also point npm install at the Pure registry if you want access to Pure-compiled native packages. See Configure npm.
Pure-compiled packages vs. standard npm packages
Section titled “Pure-compiled packages vs. standard npm packages”| Package type | How it works |
|---|---|
| Standard JavaScript/TypeScript npm packages | Included verbatim in the binary. Works for most packages. |
| Pure-compiled packages | Compiled to native code; distributed as .node add-ons from the Pure registry. Maximum performance. |
| Native add-ons (N-API) | Works if the add-on targets Node-API; does not work if it uses V8 internal headers. |
Installing packages
Section titled “Installing packages”npm install express zodNo special steps needed. After npm install, run pure build normally.
Compatibility
Section titled “Compatibility”Most pure-JavaScript npm packages work without modification. Packages that:
- Use
evalornew Function()— will not work. See Not supported. - Use unsupported Node built-ins — may not work. See Node compatibility.
- Use native add-ons — may work depending on the add-on. See below.
Native add-ons
Section titled “Native add-ons”Add-ons built with Node-API (the stable C API) generally work. Add-ons that use V8 C++ headers or Node.js internal headers do not.
Known to work:
better-sqlite3sharp(image processing)@napi-rs/*packages
Known issues:
- Packages that detect the runtime via
process.versions.nodemay misbehave if they require a specific version. You can often work around this by patching the version check.
For a detailed breakdown, see npm Packages → Native add-ons (coming soon).
Troubleshooting package issues
Section titled “Troubleshooting package issues”If a package fails to compile or behaves unexpectedly at runtime:
- Check Not supported for known limitations.
- Check Troubleshooting → Compile failures for how to read compiler output.
- Search the issue tracker for the package name.
- File a bug report with a minimal reproduction. See Support.