Search code examples
node.jsnpmnode-gypyarnpkg

Does yarn add package --build-from-source behave like npm install package --build-from-source when passing node-gyp flags to packages?


It looks like yarn does not pass node-gyp flags to native packages the way npm does.

For example when attempting to install sqlite3@3.1.6 with:

npm install sqlite3@3.1.6 \
  --build-from-source \
  --sqlite_libname=sqlcipher \
  --sqlite=`brew --prefix` \
  --verbose

we get a successful installation of sqlite3 with sqlcipher extensions, due to passing --sqlite_libname and --sqlite, which are specified in sqlite3's binding.gyp.

But, when attempting to use yarn, and running what I would think to be the equivalent command, it looks like the flags aren't honored:

yarn add sqlite3@3.1.6 \
  --force \
  --build-from-source \
  --sqlite_libname=sqlcipher \
  --sqlite=`brew --prefix` \
  --verbose

With npm unrecognized command line arguments are converted to gyp flags.

With yarn that doesn't seem to work.

Is there a way to get this functionality with yarn?


Solution

  • This is currently possible by using environment variables on the format npm_config_{snake_case_param}=true/false

    For example, npm install --build-from-source=true becomes:

    npm_config_build_from_source=true yarn install
    

    It's documented here https://yarnpkg.com/lang/en/docs/envvars/#toc-npm-config