Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundle project with sqlite3 dependency that uses prebuilt binaries #2830

Closed
gnoluna opened this issue Jan 15, 2023 · 2 comments
Closed

Bundle project with sqlite3 dependency that uses prebuilt binaries #2830

gnoluna opened this issue Jan 15, 2023 · 2 comments

Comments

@gnoluna
Copy link

gnoluna commented Jan 15, 2023

Hi there,

I encountered an issue when trying to bundle sqlite3 dependencies. The prebuilt binary is located at node_modules/sqlite3/lib/binding/napi-v6-darwin-unknown-x64/node_sqlite3.node.

In the runtime, the binary is loaded by

const binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json')));

which fails in the bundled output js because the __dirname is not referring to the module dir anymore.

the package.json in the sqlite3 module has specified the binary module

"binary": {
    "module_name": "node_sqlite3",
    "module_path": "./lib/binding/napi-v{napi_build_version}-{platform}-{libc}-{arch}",
    "host": "https://github.com/TryGhost/node-sqlite3/releases/download/",
    "remote_path": "v{version}",
    "package_name": "napi-v{napi_build_version}-{platform}-{libc}-{arch}.tar.gz",
    "napi_versions": [
      3,
      6
    ]
  },

What's the recommended way to bundle with prebuilt binaries like sqlite3?

@evanw
Copy link
Owner

evanw commented Jan 15, 2023

This is in the “getting started” instructions for node (https://esbuild.github.io/getting-started/#bundling-for-node, copied below):

You also may not want to bundle your dependencies with esbuild. There are many node-specific features that esbuild doesn't support while bundling such as __dirname, import.meta.url, fs.readFileSync, and *.node native binary modules. You can exclude all of your dependencies from the bundle by setting packages to external:

esbuild app.jsx --bundle --platform=node --packages=external

If you do this, your dependencies must still be present on the file system at run-time since they are no longer included in the bundle.

You can also mark individual packages as external if you want to do this on a case-by-case basis.

@gnoluna
Copy link
Author

gnoluna commented Jan 16, 2023

Hello @evanw Thanks for your reply. I meant to ask if it is still possible to bundle those binaries without having them at runtime. Now I know that it is not possible and the only way is to exclude them.

@gnoluna gnoluna closed this as completed Jan 16, 2023
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

No branches or pull requests

2 participants