【问题标题】:Installing the eslint pre-commit hook errors out安装 eslint 预提交钩子错误
【发布时间】:2020-10-28 11:43:31
【问题描述】:

我正在尝试安装 eslint 预提交挂钩 (https://github.com/pre-commit/mirrors-eslint)

这是我的预提交文件中的条目:

-   repo: https://github.com/pre-commit/mirrors-eslint
    rev: 'v7.4.0'
    hooks:
    -   id: eslint

但是,当我运行预提交时,我得到以下信息:

[INFO] Initializing environment for https://github.com/pre-commit/mirrors-eslint.
[INFO] Initializing environment for https://github.com/pre-commit/mirrors-eslint:eslint@7.4.0.
[INFO] Installing environment for https://github.com/pre-commit/mirrors-eslint.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: Command: ('c:\\users\\username\\appdata\\local\\programs\\python\\python38\\python.exe', '-mnodeenv', '--prebuilt', '--clean-src', '\\\\?\\C:\\Users\\username\\.cache\\pre-commit\\repow421i8dr\\node_env-default')
Return code: 1
Expected return code: 0
Output: (none)
Errors:
     * Install prebuilt node (14.5.0) ..... done.
    symbolic link created for \\?\C:\Users\username\.cache\pre-commit\repow421i8dr\node_env-default\Scripts\nodejs.exe <<===>> node.exe
     * Install npm.js (latest) ... Traceback (most recent call last):
      File "c:\users\username\appdata\local\programs\python\python38\lib\runpy.py", line 193, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "c:\users\username\appdata\local\programs\python\python38\lib\runpy.py", line 86, in _run_code
        exec(code, run_globals)
      File "c:\users\username\appdata\local\programs\python\python38\lib\site-packages\nodeenv.py", line 1462, in <module>
        main()
      File "c:\users\username\appdata\local\programs\python\python38\lib\site-packages\nodeenv.py", line 1071, in main
        create_environment(env_dir, opt)
      File "c:\users\username\appdata\local\programs\python\python38\lib\site-packages\nodeenv.py", line 911, in create_environment
        instfunc(env_dir, src_dir, opt)
      File "c:\users\username\appdata\local\programs\python\python38\lib\site-packages\nodeenv.py", line 762, in install_npm_win
        shutil.copy(join(src_dir, npm_ver, 'bin', 'npm.cmd'),
      File "c:\users\username\appdata\local\programs\python\python38\lib\shutil.py", line 415, in copy
        copyfile(src, dst, follow_symlinks=follow_symlinks)
      File "c:\users\username\appdata\local\programs\python\python38\lib\shutil.py", line 261, in copyfile
        with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
    FileNotFoundError: [Errno 2] No such file or directory: '\\\\?\\C:\\Users\\username\\.cache\\pre-commit\\repow421i8dr\\node_env-default\\src\\npm-latest\\bin\\npm.cmd'


Check the log at C:\Users\username/.cache\pre-commit\pre-commit.log

我不明白那个文件是什么或者为什么 eslint 需要它。 当我直接从终端使用 Eslint 时,它可以工作,这确认它是作为独立安装的,并且也可以按预期工作。

【问题讨论】:

    标签: git eslint pre-commit-hook pre-commit pre-commit.com


    【解决方案1】:

    您应该能够在不预先提交的情况下重现此崩溃,只需使用 nodeenv -- 尝试以下操作:

    nodeenv nenv --prebuilt --clean-src
    

    我认为这是可能的唯一方法是,如果您有一个 nodeenv 配置文件,其中包含 with_npm = truenpm = ...(一些非常旧的 npm 版本,它不提供 npm.cmd 文件)

    您可以尝试从您的配置文件中删除这些内容吗?我相信它可以在以下任何地方:

    • ./tox.ini
    • ./setup.cfg
    • %HOMEPATH%/.nodeenvrc

    【讨论】:

    • 我无法通过该评论重现错误。它只是告诉我环境已经存在。
    • 您可能需要rm -rf nenv
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-15
    • 2017-02-08
    • 2016-09-02
    相关资源
    最近更新 更多