Not being able to use !reference in include: rules:

Hello,

I have a following setup:

include:
  - local: .gitlab/job-templates.yml
  - local: projects/project1/.gitlab/job-templates.yml

  - local: .gitlab/variables/prod.yml
    rules: !reference [.prod_rules, rules]
  - local: .gitlab/variables/dev.yml
    rules: !reference [.dev_rules, rules]

some_job:
  ...

in .gitlab/job-templates.yml I have:

.dev_rules:
  rules:
    - if: $CI_COMMIT_BRANCH == "develop"
    - if: $CI_MERGE_REQUEST_ID
    - if: $CI_COMMIT_BRANCH =~ /feature/

.prod_rules:
  rules:
    - if: $CI_COMMIT_BRANCH == "master"

but when I try to run it, I get such error at the pipeline level:
Undefined error (01G3R9M7F7BJJGQEA844E4VFEF)

When I changes the above to:

include:
  - local: .gitlab/job-templates.yml
  - local: projects/project1/.gitlab/job-templates.yml

  - local: .gitlab/variables/prod.yml
    rules:
      - !reference [.prod_rules, rules]
  - local: .gitlab/variables/dev.yml
    rules: 
      - !reference [.dev_rules, rules]

some_job:
  ...

I get a similar error, just with different id:
Undefined error (01G3RA9TDZNQWZBJQ058FE0JC2)

Do you have any idea how to properly use !reference here?