如何修复 Ruby Compass(1.0.0 和 1.0.3)的 NoMethodError 问题

huangapple go评论73阅读模式
英文:

How to Fix NoMethodError Issue with Ruby Compass (1.0.0 and 1.0.3)

问题

我在Fedora 38(6.1.29-1)服务器上安装了Ruby和Compass gem。

当我尝试执行compass -h或执行任何compass编译操作时,我会收到一个NoMethodError(出现在不同的.rb文件的不同行上,但仍然是错误)。

我已经四处查找类似的错误,似乎找不到其他人也遇到这个问题。

起初,我以为是最新版本(1.0.3)的Compass不适用于我的服务器,所以我还尝试了1.0.0版本,但仍然出现相同的错误。

我还尝试在我的Windows机器上安装相同版本并按照相同的过程操作,执行相同的compass -h和compass compile命令时没有任何问题。

有人知道是什么原因导致我的Fedora服务器出现这个错误吗?

在Fedora服务器的命令行上执行"compass -h"时...

当前输出:

/home/user1/.local/share/gem/ruby/gems/compass-1.0.0/lib/compass/installers/manifest.rb的第["144"]行上的NoMethodError: Class的undefined method `exists?' for File:

预期输出:

用法:compass help [command]

描述:
  Compass样式表编写框架帮助您构建和维护样式表,并使您可以轻松使用他人提供的样式表库。

捐赠:
  Compass是慈善软件。如果您发现它有用,请捐款:http://umdf.org/compass

要获取有关特定命令的帮助,请指定该命令。

主要命令:
  * clean       - 删除生成的文件和Sass缓存
  * compile     - Sass样式表编译为CSS
  * create      - 创建新的compass项目
  * init        - compass添加到现有项目
  * watch       - 当它们更改时,将Sass样式表编译为CSS
其他命令:
  * config      - 为提供的命令行选项生成配置文件。
  * extension   - 管理您系统上的compass扩展列表
  * frameworks  - 列出可用的框架
  * help        - 获取有关compass命令或扩展的帮助
  * imports     - 发出适合传递给sass命令行的导入
  * install     - 安装扩展的模式到您的compass项目
  * interactive - 交互式评估SassScript
  * sprite      - 生成您的精灵的导入。
  * stats       - 报告有关您的样式表的统计信息
  * unpack      - 将扩展复制到扩展文件夹。
  * validate    - 验证生成的css
  * version     - 打印版本信息

可用的框架和模式:

  * compass
    - compass/ellipsis  - 跨浏览器省略截断文本的插件。
    - compass/extension - 生成compass扩展
    - compass/project   - 默认项目布局。

全局选项:
    -r, --require LIBRARY            在运行命令之前需要给定的ruby库
                                       这用于在没有项目配置文件的情况下访问compass插件
    -l, --load FRAMEWORK_DIR         加载FRAMEWORK目录中找到的框架或扩展
    -L, --load-all FRAMEWORKS_DIR    加载FRAMEWORKS_DIR目录中找到的所有框架或扩展
    -I, --import-path IMPORT_PATH    使IMPORT_PATH文件夹下的文件可被Sass的@import指令找到
    -q, --quiet                      安静模式。
        --trace                      在错误时显示完整的堆栈跟踪
        --force                      允许compass覆盖现有文件
        --boring                     关闭彩色输出。
    -?, -h, --help                   显示此消息
英文:

I have a Fedora 38 (6.1.29-1) server with Ruby and the Compass gem installed.

When I try to execute compass -h or perform any compass compiling, I get a NoMethodError (on different lines of different .rb files, but errors nonetheless).

I've looked all around for similar errors and can't seem to find anyone else that experiences this problem.

At first I thought maybe the latest version (1.0.3) of Compass doesn't work on my server, so I also tried 1.0.0 but still get the same error.

I also tried installing the same version(s) and followed the same process on my Windows machine and had no issues when executing the same compass -h and compass compile commands.

Anyone have any idea what is causing this error on my fedora server?

When executing "compass -h" on the command line on the Fedora server...

Current Output:

NoMethodError on line ["144"] of /home/user1/.local/share/gem/ruby/gems/compass-1.0.0/lib/compass/installers/manifest.rb: undefined method `exists?' for File:Class

Expected Output:

Usage: compass help [command]
Description:
The Compass Stylesheet Authoring Framework helps you
build and maintain your stylesheets and makes it easy
for you to use stylesheet libraries provided by others.
Donating:
Compass is charityware. If you find it useful please make
a tax deductable donation: http://umdf.org/compass
To get help on a particular command please specify the command.
Primary Commands:
* clean       - Remove generated files and the sass cache
* compile     - Compile Sass stylesheets to CSS
* create      - Create a new compass project
* init        - Add compass to an existing project
* watch       - Compile Sass stylesheets to CSS when they change
Other Commands:
* config      - Generate a configuration file for the provided command line options.
* extension   - Manage the list of compass extensions on your system
* frameworks  - List the available frameworks
* help        - Get help on a compass command or extension
* imports     - Emit an imports suitable for passing to the sass command-line.
* install     - Install an extension's pattern into your compass project
* interactive - Interactively evaluate SassScript
* sprite      - Generate an import for your sprites.
* stats       - Report statistics about your stylesheets
* unpack      - Copy an extension into your extensions folder.
* validate    - Validate your generated css.
* version     - Print out version information
Available Frameworks & Patterns:
* compass
- compass/ellipsis  - Plugin for cross-browser ellipsis truncated text.
- compass/extension - Generate a compass extension.
- compass/project   - The default project layout.
Global Options:
-r, --require LIBRARY            Require the given ruby LIBRARY before running commands.
This is used to access compass plugins without having a
project configuration file.
-l, --load FRAMEWORK_DIR         Load the framework or extensions found in the FRAMEWORK directory.
-L, --load-all FRAMEWORKS_DIR    Load all the frameworks or extensions found in the FRAMEWORKS_DIR directory.
-I, --import-path IMPORT_PATH    Makes files under the IMPORT_PATH folder findable by Sass's @import directive.
-q, --quiet                      Quiet mode.
--trace                      Show a full stacktrace on error
--force                      Allows compass to overwrite existing files.
--boring                     Turn off colorized output.
-?, -h, --help                   Show this message

答案1

得分: 2

File.exists? 在几个次要版本中被弃用,并一直存在到 Ruby 2.7。最终在 Ruby 3.0 中被移除。

compass gem 的最后一个版本已经超过8年了。这意味着它不再与当前版本的Ruby兼容。

您基本上有三个选择:

  1. 将您的Ruby版本降级到,例如,2.7.8。这个版本虽然不算太过时,但请注意,Ruby 2.7 已经到达了生命周期终点,将不再获得任何安全性或错误修复。
  2. 复刻 compass gem 并修复对 File.exists? 的使用,改为使用 File.exist?。这似乎是一个快速解决方案,但考虑到这个 gem 在过去8年里没有得到任何更新,您可能会发现进一步的兼容性问题或未修复的错误。
  3. 寻找替代品并替换该 gem。
英文:

File.exists? was deprecated for several minor versions and existed until Ruby 2.7. And was finally removed in Ruby 3.0.

Whereas the last version of the compass gem is more than 8 years old. That means it doesn't work with current version of Ruby anymore.

You have basically three options:

  1. Downgrade your Ruby version to, for example, 2.7.8. That version is not terrible out-dated, but keep in mind that Ruby 2.7 reached end-of-life, it will not get any security or bug fixes anymore.
  2. Fork the compass gem and fix the usage of File.exists? with File.exist?. This seems to be a quick fix, but given that this gem didn't get any update in the last 8 years, you might discover further compatibility issues or unfixed bugs.
  3. Search for an alternative and replace that gem.

huangapple
  • 本文由 发表于 2023年6月2日 03:15:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76385032.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定