Fix esbuild bundling errors caused by @mapbox/node-pre-gyp optional requires - #259
Merged
Merged
Conversation
…de-pre-gyp
Replace the runtime require('@mapbox/node-pre-gyp') in index.js with a
direct binary path computation. The module_path (./build/Release/) and
module_name (nodejieba) in package.json are static, so the binary is
always at build/Release/nodejieba.node.
This prevents esbuild from traversing @mapbox/node-pre-gyp's dependency
tree and encountering optional requires for mock-aws-s3, aws-sdk, nock,
and .html files which are not bundleable.
The @mapbox/node-pre-gyp package remains in dependencies since it is
still needed for the npm install lifecycle script.
Co-authored-by: yanyiwu <2162645+yanyiwu@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix compilation error due to missing external dependencies
Fix esbuild bundling errors caused by @mapbox/node-pre-gyp optional requires
Mar 5, 2026
yanyiwu
marked this pull request as ready for review
March 5, 2026 11:35
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When bundling apps that use
nodejiebawith esbuild, the bundler statically analyzes@mapbox/node-pre-gyp's dependency tree and fails on optional/conditionalrequire()calls ins3_setup.jsformock-aws-s3,aws-sdk,nock, and an unbundleable.htmlfile.Changes
index.js: Replace the runtimerequire('@mapbox/node-pre-gyp')+binary.find()with a direct path computation derived from the staticmodule_path/module_namevalues inpackage.json.@mapbox/node-pre-gypremains independencies— it's still invoked vianpxin theinstalllifecycle script to download/build the native binary. Removing the runtimerequire()is sufficient to prevent esbuild from traversing its dependency tree.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.