node.js - 将 node-gyp 标志传递给包时, yarn add package --build-from-source 的行为是否类似于 npm install package --build-from-source?

标签 node.js npm node-gyp yarnpkg

看起来 yarn 不像 npm 那样将 node-gyp 标志传递给 native 包。

例如,当尝试安装 sqlite3@3.1.6 时:

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

我们成功安装了带有 sqlcipher 扩展的 sqlite3,因为传递了 --sqlite_libname--sqlite,它们是 specified在 sqlite3 的 binding.gyp 中。

但是,当尝试使用 yarn 并运行我认为等效的命令时,看起来标志不被尊重:

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

使用 npm 无法识别的命令行参数被转换为 gyp 标志。

使用 yarn 似乎不起作用。

有没有办法通过 yarn 获得这个功能?

最佳答案

目前可以通过使用 npm_config_{snake_case_param}=true/false 格式的环境变量

例如,npm install --build-from-source=true 变为:

npm_config_build_from_source=true yarn install

这里记录了 https://yarnpkg.com/lang/en/docs/envvars/#toc-npm-config

关于node.js - 将 node-gyp 标志传递给包时, yarn add package --build-from-source 的行为是否类似于 npm install package --build-from-source?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45758461/

相关文章:

node.js - 我无法在 nuxt 中启动新项目

javascript - 使用 NodeJS 查找图像中是否存在 Logo

java - 尝试加载 binding.gyp 时调用 'node findJavaHome.js' 返回退出状态 1。

windows - node-expat 在 Windows 上编译但找不到模块

javascript - express /Node.js : Render custom javascript as response

node.js - 如何在 VS Code 中调试 vue js 应用程序?

node.js - karma 测试通过,但 npm 测试给出错误

c++ - npm 安装 : fatal error C1083 on bson and kerberos compilation 上的 node-gyp 错误

javascript - 程序在 page.evaluate 的嵌套循环中卡住 - Puppeteer - NodeJS

javascript - 将音频从浏览器流式传输到具有特定 MIME 类型的 Node.js 服务器