background
The current front-end project of the system is a little bit explosive~
More and more experience techniques are used in old projects. This is not a project that uses chromeDriver
Maven integrates gulp to compress js, and the frontend-maven-plugin plugin is used in the CSS scheme system, which is very useful~
question
One day my friend used chromeDriver and there was a problem
[INFO] --- frontend-maven-plugin:1.3:npm (npm install) @ appclient ---
[INFO] Running 'npm install --registry=https://registry.npm.taobao.org' in /data/jenkins/workspace/f6-local-test-mobile2.0/appclient
[INFO]
[INFO] > [email protected] install /data/jenkins/workspace/f6-local-test-mobile2.0/appclient/node_modules/chromedriver
[INFO] > node install.js
[INFO]
[INFO] Downloading https://chromedriver.storage.googleapis.com/2.35/chromedriver_linux64.zip
[INFO] Saving to /data/jenkins/workspace/f6-local-test-mobile2.0/appclient/node_modules/chromedriver/chromedriver/chromedriver_linux64.zip
[ERROR] ChromeDriver installation failed Error with http(s) request: Error: read ECONNRESET
The error is very strange. Why do you still go to chromedriver.storage.googleapis.com/? ? ?
retrieve
Sure enough, more than one friend met
When npm installs chromedriver, an error occurs occasionally, the error message is similar to:
> [email protected] install /Users/Mario/Work/Lab/waylens-all-in-one-site/node_modules/chromedriver > node install.js Downloading https://chromedriver.storage.googleapis.com/2.27/chromedriver_mac64.zip Saving to /var/folders/7l/mhhqzhps0y59by7pf04nyx5r0000gn/T/chromedriver/chromedriver_mac64.zip events.js:161 throw er; // Unhandled 'error' event ^ Error: connect ETIMEDOUT 74.125.23.128:443 at Object.exports._errnoException (util.js:1023:11) at exports._exceptionWithHostPort (util.js:1046:20) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14)
After analysis, it is found that in some versions, the response of the zip file url of chromedriver is a 302 jump, while the get method of the http object built in Node.js is used in install.js, which cannot handle the 302 jump; In other cases, it is because googleapis.com is blocked, at this time, even if the method of scientific Internet access is used, the files still cannot be obtained.
In either case, you can install it with the following command:
npm install chromedriver --chromedriver_cdnurl=http://cdn.npm.taobao.org/dist/chromedriver
It can also be installed using cnpm.
But the plugin we use does not support cnpm.
final class DefaultNpmRunner extends NodeTaskExecutor implements NpmRunner {
static final String TASK_NAME = "npm";
public DefaultNpmRunner(NodeExecutorConfig config, ProxyConfig proxyConfig, String npmRegistryURL) {
super(config, TASK_NAME, config.getNpmPath().getAbsolutePath(), buildArguments(proxyConfig, npmRegistryURL));
}
private static List<String> buildArguments(ProxyConfig proxyConfig, String npmRegistryURL) {
List<String> arguments = new ArrayList<String>();
if(npmRegistryURL != null && !npmRegistryURL.isEmpty()){
arguments.add ("--registry=" + npmRegistryURL);
}
if(!proxyConfig.isEmpty()){
Proxy proxy = null;
if(npmRegistryURL != null && !npmRegistryURL.isEmpty()){
proxy = proxyConfig.getProxyForUrl(npmRegistryURL);
}
if(proxy == null){
proxy = proxyConfig.getSecureProxy();
}
if(proxy == null){
proxy = proxyConfig.getInsecureProxy();
}
arguments.add("--https-proxy=" + proxy.getUri().toString());
arguments.add("--proxy=" + proxy.getUri().toString());
}
return arguments;
}
}
Passing parameters other than proxy and registry is also not supported! ! ! Could it be that this is a dead end?
plan
- After installing cnpm using alias and then aliasing it to npm should work
- Add the corresponding cdn_url in the npmrc environment
solve
In order to minimize the impact on other applications open rate use option 2
As follows~/.npmrc
chromedriver_cdnurl=https://npm.taobao.org/mirrors/chromedriver
[INFO] --- frontend-maven-plugin:1.3:npm (npm install) @ appclient --- [INFO] Running 'npm install --registry=https://registry.npm.taobao.org' in /data/jenkins/workspace/f6-local-test-mobile2.0/appclient
[INFO]
[INFO] > [email protected] install /data/jenkins/workspace/f6-local-test-mobile2.0/appclient/node_modules/chromedriver
[INFO] > node install.js
[INFO]
[INFO] Downloading https://npm.taobao.org/mirrors/chromedriver/2.35/chromedriver_linux64.zip
[INFO] Saving to /data/jenkins/workspace/f6-local-test-mobile2.0/appclient/node_modules/chromedriver/chromedriver/chromedriver_linux64.zip
[INFO] Received 782K...
[INFO] Received 1564K...
[INFO] Received 2346K...
[INFO] Received 3128K...
[INFO] Received 3634K total.
[INFO] Extracting zip contents