cargo / napi
napi
What changed in napi 3, from its official release notes, upgrade guides and advisories. Sources checked 2026-11-23.
21 breaking8 security1 deprecations16 new APIs and options8 behavior and defaults3 tooling59 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli initnapi 3116 changes
Breaking changes 21
Builds without type tags now reject a value of another class.
Conversion depth is bounded at 128 levels.
Addons with live native code are no longer unloaded.
The Rust version requirement is bumped.
The new @napi-rs/cli requires Node.js ^20.17.0 || ^22.13.0 || >=23.5.0 at build time; this does not change the runtime support of the shipped addon.
The compat-mode module_exports macro is replaced by #[napi(module_exports)].
Path flags are now resolved relative to --cwd or process.cwd(), rather than --cargo-cwd or process.cwd().
The --cargo-cwd flag is removed; use --manifest-path to point to the crate's Cargo.toml.
The --cargo-flags option is removed; pass Cargo flags after -- instead.
Use --manifest-path to point at the crate's Cargo.toml in place of --cargo-cwd.
Arguments after -- are forwarded to cargo build, allowing Cargo flags such as --locked to be passed through.
The command is renamed to napi create-npm-dirs.
Use napi_derive::module_init in place of napi::module_init.
Use this macro in place of the compat-mode module_exports macro; it accepts the documented signature.
The module_init macro moved from napi to napi_derive.
The command is renamed to napi universalize.
Use napi universalize in place of napi universal.
Move the package name from napi.package.name to napi.packageName; v3 does not read the old nested field.
Use a flat targets array listing every target explicitly, including targets formerly supplied by defaults.
Rust 1.88 or newer is required for the v3 migration.
ThreadsafeFunction has been rewritten, replacing its ref-count lifecycle with ownership-based behavior.
Security 8
Native payload provenance is now validated for External and instance data.
External-buffer slices now point at the engine-owned copy after finalization reclaims the source; this also affects TypedArraySlice::from_external, Uint8ClampedSlice::from_external, and compat-mode Env::create_arraybuffer_with_borrowed_data.
Wrapped payload provenance is validated before dereferencing in Object::unwrap and Object::remove_wrapped, and the deprecated Env::unwrap and Env::drop_wrapped, preventing out-of-bounds memory access.
Unexpected JavaScript value shapes now return errors instead of reaching unreachable!() and aborting the process.
Fixes a memory safety issue in PromiseRaw callbacks.
Fixes a WASI double-free involving zero-copy external strings.
Prevents async iterator use-after-free during garbage collection.
JsObject and the listed legacy JsValue types are behind compat-mode; migrate to the new APIs because these APIs are not safe.
Deprecations 1
The triples configuration is replaced by napi.targets; v3 still reads triples for compatibility, but new projects should not use it.
New APIs and options 16
Class members can use symbol_for keys.
Class members can use well-known symbol keys.
A ReadableStream can now be canceled through its Reader.
The MultiThread flavor is now available on wasm32-wasip1-threads.
Adds support for a pluggable async runtime backend.
Implementations are available for OsString, OsStr, Path and PathBuf, enabling conversions between these Rust types and napi values.
Adds a method to handle errors in callback functions.
Adds the #[napi(async_iterator)] macro attribute.
ArrayBuffer now provides unsafe as_mut, allowing mutable access to its contents.
Promise.resolve and Promise.reject are now supported.
Adds Eq and PartialEq trait implementations to BigInt.
Adds support for using node_api_create_object_with_properties for enum creation.
The napi-derive tracing feature enables debug logging of NAPI function calls.
Adds on_abort support for AbortSignal.
Enable the compat-mode feature to keep using deprecated types during an incremental migration; it is not recommended as a permanent state because those types have known safety issues.
Use napi.binaryName instead of napi.name for the binary name; napi.name remains readable for compatibility, but new projects should use binaryName.
Behavior and default changes 8
Classes marked with #[napi] have unforgeable identity via Node object type tags.
Stream now supports any object types.
Promise no longer requires tokio.
ThreadsafeFunction::call_async no longer requires tokio.
N-API symbols are loaded at runtime on all platforms using libloading.
PromiseRaw is now public.
SendableResolver is now public.
The tsfn data is now public.
Tooling 3
The CLI now supports non-threaded WASI targets.
The CLI now supports the loongarch64-unknown-linux-gnu target.
Use the renamed command to create npm/* directories in CI instead of committing those directories.
Fixes and other changes 59
AsyncTask promises no longer leak.
Teardown is handled per environment for multi-load addons.
Avoids a deadlock when a worker loads the addon during block_on.
Avoids TS1016 in constructors.
Registered classes are kept when a later load fails.
Static flags are now honored when defining classes.
Borrowed class arguments are kept alive across AsyncTask and AsyncBlock.
Failed conversion now drops an unadopted class value and resets the factory flag.
The custom GC aborted flag is set before Node closes its tsfn.
Managed array inputs are now copied.
Fixed ReadableStream::cancel.
Tokio runtime threads are joined at environment teardown.
Fixed TypedArray input leaks and compat buffer copies on wasm.
Registers wasm cleanup through the environment cleanup hook.
Objects are now created with napi_define_properties on every Node version.
The allocator is locked on threaded WASI, preventing hangs after a worker crash.
AsyncTask completion is guarded against environment teardown.
Outstanding async work is drained before the WASI binding is disposed.
Fixed fatal_exception being a no-op in optimized builds.
Converting errors keeps the anyhow error cause.
Fixed Buffer detachment in threadless wasm.
Panics in closure trampolines are caught instead of causing an abort.
Fixed waker-stack deadlocks in CurrentThread.
Module registration no longer uses randomness in wasi.
Non-Error rejections are preserved.
A teardown barrier is added for wasm.
FunctionRef is released off the JS thread via the custom-GC TSFN.
The CLI aligns build and project configuration.
Preserves the JavaScript error object when cloning an Error off-thread.
Cloning a JavaScript exception Error off-thread now preserves its message and cause.
Release Error's exception reference through the custom GC when the Error is dropped off-thread.
Stop retaining the exception object in the sync-throw path on wasm targets.
Custom-GC Buffer and TypedArray drops on another thread are routed through the owning isolate.
Changes field-error decoration for napi object attributes.
Synchronizes the referred flag when creating a weak ThreadsafeFunction.
Fixed the Reader losing chunks and aborting on errored streams.
Fixes the experimental node_api_create_object_with_properties API.
Corrects the error message typo from “non” to “none.”
Error::cause is populated from ThreadsafeFunction callee-handled callbacks.
Generator class methods are preserved.
Callback errors are handled gracefully during shutdown.
Conversion now checks for a null error_message.
Conversion from Unknown now skips nullish error causes.
Implemented TypeName for ArrayBuffer.
Fixed a memory leak in async functions.
Fixed a compile error when compiling for WASI in debug mode.
Validates status before copying in the ToNapiValue fallback.
Validates status before copying data in the env arraybuffer fallback.
Validates status before copying in the owned ToNapiValue fallback.
Validates status before copying in the remaining TypedArray fallback paths.
Fixes BigInt comparison.
Makes the NODE_VERSION_* items public again.
Restores non dyn-symbols behavior.
Fixes runtime shutdown at environment cleanup on Windows.
Fixed TypedArraySlice creation.
Fixes a memory leak in the PromiseRaw cleanup callback.
Cleans up memory issues.
Fixes node_api_create_external_string_utf16 on wasm.
Stops a reference error object on wasm targets.