18c339a94Sopenharmony_ci# External Buffer
28c339a94Sopenharmony_ci
38c339a94Sopenharmony_ci**Some runtimes other than Node.js have dropped support for external buffers**.
48c339a94Sopenharmony_ciOn runtimes other than Node.js, node-api methods may return
58c339a94Sopenharmony_ci`napi_no_external_buffers_allowed` to indicate that external
68c339a94Sopenharmony_cibuffers are not supported. One such runtime is Electron as
78c339a94Sopenharmony_cidescribed in this issue
88c339a94Sopenharmony_ci[electron/issues/35801](electron/electron/issues/35801).
98c339a94Sopenharmony_ci
108c339a94Sopenharmony_ciIn order to maintain broadest compatibility with all runtimes,
118c339a94Sopenharmony_ciyou may define `NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED` in your addon before
128c339a94Sopenharmony_ciincludes for the node-api and node-addon-api headers. Doing so will hide the
138c339a94Sopenharmony_cifunctions that create external buffers. This will ensure a compilation error
148c339a94Sopenharmony_cioccurs if you accidentally use one of these methods.
158c339a94Sopenharmony_ci
168c339a94Sopenharmony_ciIn node-addon-api, the `Napi::Buffer::NewOrCopy` provides a convenient way to
178c339a94Sopenharmony_cicreate an external buffer, or allocate a new buffer and copy the data when the
188c339a94Sopenharmony_ciexternal buffer is not supported.
19