2

My node.js project has a dependency on node-sqlite, but unfortunately the default libsqlite binary embedded there was not built with options I need.

Now I can invoke npm install on that package alone to get it to build correctly:

CFLAGS=-DSQLITE_ENABLE_STAT4 npm install sqlite3 --build-from-source

Essentially, this sets the environment variable and passes an option to the tool.

However, npm install by itself should just install all the project dependencies, including sqlite. How do I encode package.json or elsewhere so that npm install will install the sqlite dependency with the above command line?

jww
  • 97,681
  • 90
  • 411
  • 885
Glen Low
  • 4,379
  • 1
  • 30
  • 36

1 Answers1

2

You could use a preinstall or a postinstall script to do this.

#!/bin/bash

CFLAGS=-DSQLITE_ENABLE_STAT4 npm install sqlite3 --build-from-source;

Put this in scripts/install_sqlite3_from_source.sh, and set scripts.preinstall or scripts.postinstall in your package.json to it.

elssar
  • 5,651
  • 7
  • 46
  • 71
  • Hmm... doesn't this duplicate the package installing that `npm install` does? i.e. `npm install` would end up installing sqlite twice. – Glen Low Jan 16 '16 at 04:14
  • Oh, you'll have to remove `sqlite3` from your dependences – elssar Jan 16 '16 at 04:16