文章

遇到的问题

问题1: Deprecation Warning: Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
> jekyll server

Configuration file: /Users/FengYLBook/DataStorage/My_Info/FSGit/jekyllblog/blog/_config.yml
            Source: /Users/FengYLBook/DataStorage/My_Info/FSGit/jekyllblog/blog
       Destination: /Users/FengYLBook/DataStorage/My_Info/FSGit/jekyllblog/blog/_site
 Incremental build: disabled. Enable with --incremental
      Generating... 
       Jekyll Feed: Generating feed for posts
Deprecation Warning: Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.

Recommendation: math.div($spacing-unit, 2) or calc($spacing-unit / 2)

More info and automated migrator: https://sass-lang.com/d/slash-div

   ╷
40 │   margin-bottom: $spacing-unit / 2;
   │                  ^^^^^^^^^^^^^^^^^
   ╵
    ../../../../minima-2.5.1/_sass/minima/_base.scss 40:18                            @import
    minima.scss 48:3                                                                  @import
    /Users/FengYLBook/DataStorage/My_Info/FSGit/jekyllblog/blog/assets/main.scss 1:9  root stylesheet

原因:
使用一个被弃用的语法,即在除了 calc() 函数之外的地方使用 / 进行除法运算
目录: /opt/homebrew/lib/ruby/gems/3.1.0/gems/minima-2.5.1/_sass/minima/_base.scss
  #这一行 计算方式有问题
  margin-bottom: $spacing-unit / 2;

解决:
在 博客根目录的配置文件 _config.yaml 中,添加以下行:
=============================================
sass:
  quiet_deps: true
=============================================
目的: 禁用依赖项的警告信息,而不会禁用其他类型的警告或错误信息

问题2: ‘search_up’: undefined method `untaint’ for “//“:String

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/opt/homebrew/lib/ruby/gems/3.2.0/gems/bundler-1.16.1/lib/bundler/shared_helpers.rb:266:in `search_up': undefined method `untaint' for "/Users/FengYLBook/DataStorage/My_Info/FSGit/jekyllblog/blog":String (NoMethodError)

      current  = File.expand_path(SharedHelpers.pwd).untaint
                                                    ^^^^^^^^

原因: 错误是因为在Ruby 3.2.0中,untaint方法已经被移除了,但是你的Bundler版本(1.16.1)仍然在使用这个方法。解决这个问题的最简单方法是升级你的Bundler到一个与Ruby 3.2.0兼容的版本

解决: 根据查找资料发现 ruby2.7.0支持这个方法,所以需要安装一下ruby2.7.0
1. 安装: rbenv, 可以切换ruby版本
    brew install rbenv
2. 安装Ruby指定版本:
    rbenv install 2.7.8
    # 安装指定版本的时候如果不行,可以试试其他大小版本; mac安装2.7.0时编译不通过,换2.7.8就好了
1. 切换当前 Ruby版本:
    rbenv local 版本号
    # 比如: rbenv local 2.7.8

问题3: Deprecation Warning: Sass @import rules are deprecated and will be removed in Dart Sass 3.0.0.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Deprecation Warning: Sass @import rules are deprecated and will be removed in Dart Sass 3.0.0.

More info and automated migrator: https://sass-lang.com/d/import

  ╷
1 │ @import 'main';
  │         ^^^^^^
  ╵
    /Users/fengshao/DataStorage/My_Info/FSGit/jekyllblog/jekyll-theme-chirpy/assets/css/jekyll-theme-chirpy.scss 1:9  root stylesheet
                    done in 12.315 seconds.
 Auto-regeneration: disabled. Use --watch to enable.

==================================================================================
根本原因:
Sass 目前推荐使用 @use 和 @forward 来替代传统的 @import。@import 语法会在未来的 Dart Sass 版本中被移除。你看到的这个警告表明,代码中仍在使用 @import。

解决方案:
将 @import 替换为 @use

@import 'main';

修改为
@use 'main' as *;
或者 保留命名空间:
@use 'main';

==================================================================================
备注:
关于 @use 和 @import 的区别:
@import:它会将导入的文件内容直接插入到当前文件中,并且所有的变量、函数等都会被引入到全局作用域中,这可能会导致命名冲突。

@use:它会将导入的文件限定在一个命名空间中,不会污染全局作用域。你需要使用命名空间来访问文件中的变量、混合宏、函数等。


本文由作者按照 CC BY 4.0 进行授权