yarn 安装依赖报错问题记录

378 阅读2分钟

报错信息

error C:\Users\Administrator\Desktop\react\node_modules\gifsicle: Command failed.
Exit code: 1
Command: node lib/install.js
Arguments:
Directory: C:\Users\Administrator\Desktop\react\node_modules\gifsicle
Output:
‼ getaddrinfo ENOENT raw.githubusercontent.com
  ‼ gifsicle pre-build test failed
  i compiling from source
  × Error: Command failed: C:\WINDOWS\system32\cmd.exe /s /c "autoreconf -ivf"
'autoreconf' �����ڲ����ⲿ���Ҳ���ǿ����еij���

查看 gifsicle,是个 gif 图片压缩的命令行工具。通过手动安装也不行。没法子了,只能开进去看看具体报错文件。

看上面信息说的是C:\Users\Administrator\Desktop\react\node_modules\gifsicle这个文件夹下面的lib/install.js这个脚本里面有命令执行失败了,具体什么问题还不清楚,所以应该去找到这个文件去看一下。

'use strict';
const path = require('path');
const binBuild = require('bin-build');
const log = require('logalot');
const bin = require('.');

(async () => {
    try {
        await bin.run(['--version']);
        log.success('gifsicle pre-build test passed successfully');
    } catch (error) {
        log.warn(error.message);
        log.warn('gifsicle pre-build test failed');
        log.info('compiling from source');

        const config = [
            './configure --disable-gifview --disable-gifdiff',
            `--prefix="${bin.dest()}" --bindir="${bin.dest()}"`
        ].join(' ');

        try {
            await binBuild.file(path.resolve(__dirname, '../vendor/source/gifsicle-1.92.tar.gz'), [
                'autoreconf -ivf',
                config,
                'make install'
            ]);

            log.success('gifsicle built successfully');
        } catch (error) {
            log.error(error.stack);

            // eslint-disable-next-line unicorn/no-process-exit
            process.exit(1);
        }
    }
})();

在看我们的报错中有这个错误信息 gifsicle pre-build test failed,所以应该是bin.run(['--version'])这行代码有问题导致产生了这个报错。 在往上找 bin这个模块

'use strict';
const path = require('path');
const BinWrapper = require('bin-wrapper');
const pkg = require('../package.json');

const url = `https://raw.githubusercontent.com/imagemin/gifsicle-bin/v${pkg.version}/vendor/`;

module.exports = new BinWrapper()
    .src(`${url}macos/gifsicle`, 'darwin')
    .src(`${url}linux/x86/gifsicle`, 'linux', 'x86')
    .src(`${url}linux/x64/gifsicle`, 'linux', 'x64')
    .src(`${url}freebsd/x86/gifsicle`, 'freebsd', 'x86')
    .src(`${url}freebsd/x64/gifsicle`, 'freebsd', 'x64')
    .src(`${url}win/x86/gifsicle.exe`, 'win32', 'x86')
    .src(`${url}win/x64/gifsicle.exe`, 'win32', 'x64')
    .dest(path.join(__dirname, '../vendor'))
    .use(process.platform === 'win32' ? 'gifsicle.exe' : 'gifsicle');

这个文件的意思应该是根据不同的环境系统下载不同的一个可执行文件,首先去看文件下载下来了吗,去看vendor文件夹,没有这个文件,证明这步出错了。再回头看报错信息第一行报错信息是getaddrinfo ENOENT raw.githubusercontent.com,getaddrinfo是获取地址信息,ENOENT是大写的,像是一个专业术语,所以直接百度,应该有的,这个是一个缩写,全称是Error No Entry,没有这个的目录的意思,再结合后面那个网址,所以应该是脚本运行的时候没有找到正确的下载地址,有可能是被墙了,这个时候考虑代理的问题,我电脑是开了代理的,但是我yarn好像没设置代理,所以可以试着给yarn设置代理

$ yarn config set proxy http://127.0.0.1:7890/

再重新运行yarn安装依赖,ok没问题。