Skip to content

chore(cli): throw error if wasi file not found when NAPI_RS_FORCE_WASI=error#2919

Merged
Brooooooklyn merged 2 commits into
mainfrom
09-11-chore_cli_throw_error_if_wasi_file_not_found_when_napi_rs_force_wasi_error
Sep 11, 2025
Merged

chore(cli): throw error if wasi file not found when NAPI_RS_FORCE_WASI=error#2919
Brooooooklyn merged 2 commits into
mainfrom
09-11-chore_cli_throw_error_if_wasi_file_not_found_when_napi_rs_force_wasi_error

Conversation

@Brooooooklyn

@Brooooooklyn Brooooooklyn commented Sep 11, 2025

Copy link
Copy Markdown
Member

Copy link
Copy Markdown
Member Author

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • ready-to-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@Brooooooklyn
Brooooooklyn force-pushed the 09-11-chore_cli_throw_error_if_wasi_file_not_found_when_napi_rs_force_wasi_error branch from aa8b785 to ee2f5f5 Compare September 11, 2025 08:03
@Brooooooklyn
Brooooooklyn force-pushed the 09-11-chore_cli_throw_error_if_wasi_file_not_found_when_napi_rs_force_wasi_error branch from ee2f5f5 to bb4eee5 Compare September 11, 2025 08:18
@Brooooooklyn

Copy link
Copy Markdown
Member Author

cursor review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a new error handling mechanism for WASI file loading when NAPI_RS_FORCE_WASI=error is set. The change addresses issue #2918 by adding explicit error throwing when WASI binding files are not found in error mode.

  • Adds error throwing when NAPI_RS_FORCE_WASI=error and WASI binding files cannot be loaded
  • Refactors WASI binding loading logic to track binding state and errors more precisely
  • Updates package dependencies across multiple workspace packages

Reviewed Changes

Copilot reviewed 15 out of 18 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
cli/src/api/templates/js-binding.ts Implements the core WASI error handling logic with improved error tracking
examples/napi/index.cjs Generated binding file reflecting the new error handling template
examples/napi/index.d.cts Adds ReadableStream type import for better TypeScript support
examples/napi/tests/values.spec.ts Updates comment for ReadableStream polyfill type conflict
examples/napi/browser/values.spec.ts Adds generic type parameter to Promise.withResolvers
examples/napi/tsconfig.json Updates types configuration from bun-types to node
package.json, */package.json Updates various package dependencies to newer versions

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread cli/src/api/templates/js-binding.ts
Comment thread examples/napi/index.cjs
Comment thread examples/napi/index.cjs
Comment thread cli/src/api/templates/js-binding.ts
Comment thread cli/src/api/templates/js-binding.ts
@Brooooooklyn
Brooooooklyn merged commit 8120ca0 into main Sep 11, 2025
72 checks passed
@Brooooooklyn
Brooooooklyn deleted the 09-11-chore_cli_throw_error_if_wasi_file_not_found_when_napi_rs_force_wasi_error branch September 11, 2025 08:29
MukundaKatta added a commit to MukundaKatta/napi-rs that referenced this pull request Apr 15, 2026
The generated native.js template treated process.env.NAPI_RS_FORCE_WASI as a
plain truthy-string check. In JavaScript any non-empty string is truthy,
including 'false' and '0', so setting NAPI_RS_FORCE_WASI=false (intending
to opt out of forced WASI) inadvertently triggered the WASI fallback — the
same path that tries to load <pkg>.wasi.cjs and fails with ENOENT for
packages that don't ship a WASI binding.

Reported by lancedb/lancedb#3267, where downstream users hit:

  ENOENT: no such file or directory, open '.../@lancedb/lancedb/dist/lancedb.wasi.cjs'

This patch extracts a single `forceWasi` boolean at the top of the
generated script (equal to 'true' or 'error') and uses it consistently
at the four call sites that previously did a truthy-string check. The
existing `=== 'error'` branch at the bottom is preserved unchanged — it
already did the right thing.

This is a template change, so the fix is picked up the next time a
downstream package runs `napi build`. No behavior change for
existing users who had NAPI_RS_FORCE_WASI unset or set to 'true'/'error'.

Related: PR napi-rs#2919 added the 'error' tri-state; this patch completes
the tri-state handling by making the other two values ('true' and
everything-else) behave as documented.

Signed-off-by: Mukunda Katta <[email protected]>
Brooooooklyn pushed a commit that referenced this pull request May 26, 2026
The generated native.js template treated process.env.NAPI_RS_FORCE_WASI as a
plain truthy-string check. In JavaScript any non-empty string is truthy,
including 'false' and '0', so setting NAPI_RS_FORCE_WASI=false (intending
to opt out of forced WASI) inadvertently triggered the WASI fallback — the
same path that tries to load <pkg>.wasi.cjs and fails with ENOENT for
packages that don't ship a WASI binding.

Reported by lancedb/lancedb#3267, where downstream users hit:

  ENOENT: no such file or directory, open '.../@lancedb/lancedb/dist/lancedb.wasi.cjs'

This patch extracts a single `forceWasi` boolean at the top of the
generated script (equal to 'true' or 'error') and uses it consistently
at the four call sites that previously did a truthy-string check. The
existing `=== 'error'` branch at the bottom is preserved unchanged — it
already did the right thing.

This is a template change, so the fix is picked up the next time a
downstream package runs `napi build`. No behavior change for
existing users who had NAPI_RS_FORCE_WASI unset or set to 'true'/'error'.

Related: PR #2919 added the 'error' tri-state; this patch completes
the tri-state handling by making the other two values ('true' and
everything-else) behave as documented.

Signed-off-by: Mukunda Katta <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support throwing error if wasi binding is not found with NAPI_RS_FORCE_WASI=error or NAPI_RS_FORCE_WASI=1

2 participants