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

【node-pre-gyp执行的binary文件下载不了怎么办?】 #57

Open
kind-hearted opened this issue Aug 22, 2018 · 0 comments
Open

Comments

@kind-hearted
Copy link
Owner

kind-hearted commented Aug 22, 2018

node-pre-gyp位于npm和node-gyp之间,提供了一种跨平台的二进制部署方法。

有些npm包中存在二进制文件,并在npm install的时候执行node-pre-gyp安装二进制的C++模块,在其package.json文件夹通常有一个binary字段,安装时会去服务器拉取二进制文件。

以sqlite3为例

{
  "binary": {
    "module_name": "node_sqlite3",
    "module_path": "./lib/binding/{node_abi}-{platform}-{arch}",
    "host": "https://mapbox-node-binary.s3.amazonaws.com",
    "remote_path": "./{name}/v{version}/{toolset}/",
    "package_name": "{node_abi}-{platform}-{arch}.tar.gz"
  }
}

由于网络原因(公司限制、国家限制),下载二进制文件失败会导致整个包安装失败。如何解决?

先到https://npm.taobao.org/mirrors找找没有镜像文件,一般都有,sqlite3存在。

安装

// --{module_name}_binary_host_mirror={host}
npm install sqlite3 --node_sqlite3_binary_host_mirror=https://npm.taobao.org/mirrors

安装时可能会报错:

node-pre-gyp ERR! Tried to download(302): https://npm.taobao.org/mirrors/sqlite3/v4.0.0/node-v57-win32-x64.tar.gz

应该是302重定向导致了,直接在浏览器访问https://npm.taobao.org/mirrors/sqlite3/v4.0.0/node-v57-win32-x64.tar.gz,得到重定向后的地址http://cdn.npm.taobao.org/dist/sqlite3/v4.0.0/node-v57-win32-x64.tar.gz

再次安装:

npm install sqlite3 --node_sqlite3_binary_host_mirror=http://cdn.npm.taobao.org/dist/

安装成功!

使用yarn执行以下语句,无法安装!!!待解决!

yarn add sqlite3 --node_sqlite3_binary_host_mirror=http://cdn.npm.taobao.org/dist/
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

1 participant