xxxxxxxxxx
// Module path
$module_handler = \Drupal::service('module_handler');
$module_path = $module_handler->getModule('my_module')->getPath();
xxxxxxxxxx
$module_handler = \Drupal::service('module_handler');
$module_path = $module_handler->getModule('my_module')->getPath();
#Alternative
$module_path = \Drupal::service('extension.list.module')->getPath('MODULE_NAME');
xxxxxxxxxx
$module_handler = \Drupal::service('module_handler');
$module_path = $module_handler->getModule('my_module')->getPath();
xxxxxxxxxx
$build['#attached']['drupalSettings']['mymodule']['mylib']['path'] = \Drupal::service('extension.list.module')->getPath('mymodule');