Unable to use file provider (chain cannot be a standalone element (type *dynamic.Chain))

Hi, I'm trying to get traefik 2.5.4 to read my configuration file, but it's not working.

docker-compose.yml

volumes:
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /home/<username>/traefik/data/traefik.yml:/traefik.yml:ro
      - /home/<username>/traefik/data/acme.json:/acme.json
      - /home/<username>/traefik/config.yml:/config.yml:ro

traefik.yml

providers:
  docker:
    exposedByDefault: false
    endpoint: "unix:///var/run/docker.sock"

  file:
    filename: /config.yml
    watch: true

On container startup this is the error I'm seeing in the log:

time="2021-12-10T12:51:45Z" level=info msg="Starting provider *file.Provider {\"watch\":true,\"filename\":\"/config.yml\"}"
time="2021-12-10T12:51:45Z" level=error msg="Cannot start the provider *file.Provider: chain cannot be a standalone element (type *dynamic.Chain)"

Thank you so much for your help!

I also tried to configure the file provider as directory, but I get exactly the same error:

time="2021-12-10T16:05:53Z" level=error msg="Cannot start the provider *file.Provider: /conf/dynamic_conf.yml: chain cannot be a standalone element (type *dynamic.Chain)"

Any help with this would be much appreciated!

Ok, I found the issue. There was a mistake in my dynamic configuration file, specifically I missed one mandatory subsection in one of the middlewares:

    middlewareX:
      chain:
          - foo
          - bar

I fixed it by changing it to:

    middlewareX:
      chain:
        middlewares:
          - foo
          - bar

I hope this will help someone in the same situation.