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

Preparing NodeJS windows executable with better-sqlite3 dependency #534

Closed
Chandan-Adiga-EMRx opened this issue Jan 11, 2021 · 2 comments
Closed

Comments

@Chandan-Adiga-EMRx
Copy link

Chandan-Adiga-EMRx commented Jan 11, 2021

OS: Windows 10 (64bit)
NodeJS version: V-14.15.1
better-sqlite3 version: 7.1.1

We are using gulp to build and prepare windows executable(EXE) file for our NodeJS webapp.
Recently we have migrated from node-sqlite3 to better-sqlite3. we are also able to install better-sqlite3 successfully on windows and our backend with better-sqlite3 performing better! Thank you!!

Earlier, we have resolved node-sqlite3 dependency using below gulp file task

...
gulp.task("copySqliteBinary", function () {
  const sqliteBinaryPath = binary.find(
    path.resolve(
      path.join(buildPath, "node_modules", "sqlite3", "package.json")
    )
  );

  return gulp.src(sqliteBinaryPath).pipe(gulp.dest(buildPath));
});

gulp.task("updateSqliteNodeReference", (done) => {
  const bindingPath = path.join(
    buildPath,
    "node_modules",
    "sqlite3",
    "lib",
    "sqlite3-binding.js"
  );
  fs.writeFileSync(
    bindingPath,
    `module.exports = require('./node_sqlite3.node')`
  );
  done();
});
...

Now, we are not sure how to resolve better-sqlite3 dependency to prepare windows executable(For same platoforms i.e windows 10 64bit). Appreciate any help in resolving this dependency.

Thanks,
Chandan

@Chandan-Adiga-EMRx Chandan-Adiga-EMRx changed the title Exporting Application build with better-sqlite3 dependency Preparing NodeJS windows executable with better-sqlite3 dependency Jan 11, 2021
@Rajesh-PD-EMRx
Copy link

I am also facing same issue

Error: Could not locate the bindings file. Tried:
 → E:\snapshot\build\node_modules\better-sqlite3\build\better_sqlite3.node
 → E:\snapshot\build\node_modules\better-sqlite3\build\Debug\better_sqlite3.node
 → E:\snapshot\build\node_modules\better-sqlite3\build\Release\better_sqlite3.node
 → E:\snapshot\build\node_modules\better-sqlite3\out\Debug\better_sqlite3.node
 → E:\snapshot\build\node_modules\better-sqlite3\Debug\better_sqlite3.node
 → E:\snapshot\build\node_modules\better-sqlite3\out\Release\better_sqlite3.node
 → E:\snapshot\build\node_modules\better-sqlite3\Release\better_sqlite3.node
 → E:\snapshot\build\node_modules\better-sqlite3\build\default\better_sqlite3.node
 → E:\snapshot\build\node_modules\better-sqlite3\compiled\14.4.0\win32\x64\better_sqlite3.node
 → E:\snapshot\build\node_modules\better-sqlite3\addon-build\release\install-root\better_sqlite3.node
 → E:\snapshot\build\node_modules\better-sqlite3\addon-build\debug\install-root\better_sqlite3.node
 → E:\snapshot\build\node_modules\better-sqlite3\addon-build\default\install-root\better_sqlite3.node
 → E:\snapshot\build\node_modules\better-sqlite3\lib\binding\node-v83-win32-x64\better_sqlite3.node
    at bindings (E:\snapshot\build\node_modules\bindings\bindings.js:126:9)
    at Object.<anonymous> (E:\snapshot\build\node_modules\better-sqlite3\lib\database.js:9:24)
    at Module._compile (pkg/prelude/bootstrap.js:1320:22)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1218:10)
    at Module.load (internal/modules/cjs/loader.js:1047:32)
    at Function.Module._load (internal/modules/cjs/loader.js:935:14)
    at Module.require (internal/modules/cjs/loader.js:1087:19)
    at Module.require (pkg/prelude/bootstrap.js:1225:31)
    at require (internal/modules/cjs/helpers.js:73:18)
    at Object.<anonymous> (E:\snapshot\build\node_modules\better-sqlite3\lib\index.js:2:18) {
  tries: [
    'E:\\snapshot\\build\\node_modules\\better-sqlite3\\build\\better_sqlite3.node',
    'E:\\snapshot\\build\\node_modules\\better-sqlite3\\build\\Debug\\better_sqlite3.node',
    'E:\\snapshot\\build\\node_modules\\better-sqlite3\\build\\Release\\better_sqlite3.node',
    'E:\\snapshot\\build\\node_modules\\better-sqlite3\\out\\Debug\\better_sqlite3.node',
    'E:\\snapshot\\build\\node_modules\\better-sqlite3\\Debug\\better_sqlite3.node',
    'E:\\snapshot\\build\\node_modules\\better-sqlite3\\out\\Release\\better_sqlite3.node',
    'E:\\snapshot\\build\\node_modules\\better-sqlite3\\Release\\better_sqlite3.node',
    'E:\\snapshot\\build\\node_modules\\better-sqlite3\\build\\default\\better_sqlite3.node',
    'E:\\snapshot\\build\\node_modules\\better-sqlite3\\compiled\\14.4.0\\win32\\x64\\better_sqlite3.node',
    'E:\\snapshot\\build\\node_modules\\better-sqlite3\\addon-build\\release\\install-root\\better_sqlite3.node',
    'E:\\snapshot\\build\\node_modules\\better-sqlite3\\addon-build\\debug\\install-root\\better_sqlite3.node',
    'E:\\snapshot\\build\\node_modules\\better-sqlite3\\addon-build\\default\\install-root\\better_sqlite3.node',
    'E:\\snapshot\\build\\node_modules\\better-sqlite3\\lib\\binding\\node-v83-win32-x64\\better_sqlite3.node'
  ]
}

@Chandan-Adiga-EMRx
Copy link
Author

We were able to resolve the dependency for gulp build using below methods.

  1. better-sqlite3 node dependency file is 'better_sqlite3.node', which is present @ node_modules\better-sqlite3\build\Release\better_sqlite3.node.
  2. Have written gulp script to copy it to out/target folder as below:
gulp.task("copySqliteBinary", function () {
  // considering node file is generate and placed at node_modules\better-sqlite3\build\Release\better_sqlite3.node
  //buildPath -> your target EXE build path.
  const sqliteBinaryPath = path.join("node_modules", "better-sqlite3", "build", "Release", "better_sqlite3.node")
  return gulp.src(sqliteBinaryPath).pipe(gulp.dest(buildPath));
});

  1. Have written gulp script to update the file referring above .node dependency as below:
gulp.task("updateSqliteNodeReference", () => {
  // Node Dependency is linked in database.js file which is here: node_modules\better-sqlite3\lib
  const bindingFilePath = path.join(
    buildPath,
    "node_modules",
    "better-sqlite3",
    "lib",
  );
  const bindingFile = path.join(bindingFilePath, "database.js")
  return gulp.src([bindingFile])
    .pipe(replace(`require('bindings')('better_sqlite3.node');`, `require('./better_sqlite3.node')`))
    .pipe(gulp.dest(bindingFilePath))
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants