0

I've written a custom module that uses jwt.transcoder service from the jwt module. In turn, it provides another service:

$ cat mymodule.services.yml
services:
  mymodule.jwt:
    class: Drupal\mymodule\Services\Jwt
    arguments: [ '@jwt.transcoder', '@event_dispatcher' ]

Everything went smoothly during development. However, neither the jwt module, nor my new custom module, were installed on our site before I started developing this feature.

I added both modules with composer, and did a config export to enable them (and set up the cryptographic keys, etc). However, when I go to do a deployment, I get an error on the config import, which apparently is coming from a dependency on the jwt.transcoder service, which is not yet installed at this point.

In CheckExceptionOnInvalidReferenceBehaviorPass.php line 86:
                                                                                      
  The service "mymodule.jwt" has a dependency on a non-existent service "jwt.transcoder". 

With our deploy process, we can only deploy one codebase at a time-- meaning that, if I wanted to do a config import to get jwt installed first, and another config import with the enabling of my custom module, I would have to do a second deploy to do get that second config codebase up on the server.

Is there any way to get the config import to install jwt first, and then my custom module, in a single codebase, so this dependency is resolved?

2
  • 2
    Is "jwt" marked as a dependency of "mymodule" in mymodule.info.yml?
    – sonfd
    Mar 24, 2022 at 16:09
  • @sonfd that was it! Thank you. Please put that in an answer and I will accept it : )
    – user1359
    Mar 24, 2022 at 16:25

1 Answer 1

3

You need to mark the jwt module as a dependency of mymodule in mymodule.info.yml, via the dependencies key.

dependencies: a list of other modules your module depends on. Dependencies on Drupal core or contrib modules should be namespaced in the format {project}:{module}, where {project} is the project name as it appears in the Drupal.org URL (e.g. drupal.org/project/views) and {module} is the module's machine name. Dependencies can also include version restrictions, for examplewebform:webform (>=8.x-5.x). Note that if your module has dependencies on other contributed modules or libraries, these should be declared in the module's composer.json file. If you have local custom modules that are dependent on each other you can use {module}:{module} (or {module}:{submodule} for sub-modules.)

Source: Let Drupal know about your module with an .info.yml file

For example, inside your mymodule.info.yml:

name: My Module
type: module
...
dependencies:
  - jwt:jwt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.