有一台内网机器,机器1,这台机器连接不上外网,这台机器上需要进行内网的前端项目的构建打包,
机器1 通过设置私库地址:
npm config set registry http://**.**.**.**/repository/npm-group/
// http://**.**.**.**/repository/npm-group/ registry 地址
去下载前端所需要的依赖;
但是由于前端的项目中用到了node-sass ;
在执行
npm install
的时候,就会遇到以下情况:
> node-sass@4.9.3 install /demo/code/master/node_modules/node-sass
> node scripts/install.js
Downloading binary from https://github.com/sass/node-sass/releases/download/v4.9.3/linux-x64-64_binding.node
Cannot download "https://github.com/sass/node-sass/releases/download/v4.9.3/linux-x64-64_binding.node":
ETIMEDOUT
Timed out attemping to establish a remote connection
Hint: If github.com is not accessible in your location
try setting a proxy via HTTP_PROXY, e.g.
export HTTP_PROXY=http://example.com:1234
or configure npm proxy via
npm config set proxy http://example.com:8080
这个时候,需要通过连接github去下载linux-x64-64_binding.node这个依赖;但是由于连接不上外网,所以导致连接超时,npm install 失败。
解决办法1:
设置系统代理:
export HTTP_PROXY=http://**.**.**.**/repository/npm-group/
// registry 的地址 http://**.**.**.**/repository/npm-group/
或者设置npm 代理:
npm config set proxy http://**.**.**.**/repository/npm-group/
// registry 的地址 http://**.**.**.**/repository/npm-group/
设置binding.node下载变量:
export SASS_BINARY_SITE=https://npm.taobao.org/mirrors/node-sass
此时在执行 npm install 就会发现不会报错,完美执行。
由于node10.x.x的版本,node-gyp会报错如下错误;
Building: /usr/local/bin/node /data/devops/jenkins/workspace/app/xinyewu/pimp/pimp-vue/code/pimp-vue-dev-201904/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
gyp info it worked if it ends with ok
gyp verb cli [ '/usr/local/bin/node',
gyp verb cli '/data/devops/jenkins/workspace/app/xinyewu/pimp/pimp-vue/code/pimp-vue-dev-201904/node_modules/node-gyp/bin/node-gyp.js',
gyp verb cli 'rebuild',
gyp verb cli '--verbose',
gyp verb cli '--libsass_ext=',
gyp verb cli '--libsass_cflags=',
gyp verb cli '--libsass_ldflags=',
gyp verb cli '--libsass_library=' ]
gyp info using node-gyp@3.8.0
gyp info using node@10.15.3 | linux | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` succeeded python2 /usr/bin/python2
gyp verb check python version `/usr/bin/python2 -c "import sys; print "2.7.13
gyp verb check python version .%s.%s" % sys.version_info[:3];"` returned: %j
gyp verb get node dir no --target version specified, falling back to host node version: 10.15.3
gyp verb command install [ '10.15.3' ]
gyp verb install input version string "10.15.3"
gyp verb install installing version: 10.15.3
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version not already installed, continuing with install 10.15.3
gyp verb ensuring nodedir is created /root/.node-gyp/10.15.3
gyp verb created nodedir /root/.node-gyp
gyp http GET https://nodejs.org/download/release/v10.15.3/node-v10.15.3-headers.tar.gz
gyp verb download using proxy url: "http://xx.xxx.xx.xx/"
gyp WARN install got an error, rolling back install
gyp verb command remove [ '10.15.3' ]
gyp verb remove using node-gyp dir: /root/.node-gyp
gyp verb remove removing target version: 10.15.3
gyp verb remove removing development files for version: 10.15.3
gyp ERR! configure error
gyp ERR! stack Error: tunneling socket could not be established, statusCode=400
gyp ERR! stack at ClientRequest.onConnect (/data/devops/jenkins/workspace/app/xinyewu/pimp/pimp-vue/code/pimp-vue-dev-201904/node_modules/tunnel-agent/index.js:166:19)
gyp ERR! stack at Object.onceWrapper (events.js:277:13)
gyp ERR! stack at ClientRequest.emit (events.js:189:13)
gyp ERR! stack at Socket.socketOnData (_http_client.js:475:11)
gyp ERR! stack at Socket.emit (events.js:189:13)
gyp ERR! stack at addChunk (_stream_readable.js:284:12)
gyp ERR! stack at readableAddChunk (_stream_readable.js:265:11)
gyp ERR! stack at Socket.Readable.push (_stream_readable.js:220:10)
gyp ERR! stack at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
gyp ERR! System Linux 3.10.0-862.14.4.el7.x86_64
gyp ERR! command "/usr/local/bin/node" "/data/devops/jenkins/workspace/app/xinyewu/pimp/pimp-vue/code/pimp-vue-dev-201904/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /data/devops/jenkins/workspace/app/xinyewu/pimp/pimp-vue/code/pimp-vue-dev-201904/node_modules/node-sass
gyp ERR! node -v v10.15.3
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
Build failed with error code: 1
npm WARN ajv-keywords@3.2.0 requires a peer of ajv@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.11.0 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@4.11.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2019-03-30T07_07_43_194Z-debug.log