Magento2: Cannot uninstall 3th party module. Magento reads location of composer.json wrong

Created on 14 Apr 2017  路  3Comments  路  Source: magento/magento2

Preconditions

  1. Magento 2.1.x
  2. PHP 7.0.14
  3. MySQL 5.7.16

Steps to reproduce

  1. Have a custom module with the following structure.
  2. composer.json
  3. registration.php
  4. src
  5. in registration.php have the dir as: __DIR__.'/src'
  6. in composer.json have psr-4 as: "Vendor\\Module\\": "src/"
  7. have some installSchema, installData file in src\Setup
  8. have a Uninstall file in src\Setup
  9. run: bin/magento module:uninstall Vendor_Module --remove-data

Expected result

  1. It should properly find the composer.json file and uninstall the module

Actual result

  1. Exits with error: Vendor_Module is not an installed composer package

But if you add a composer.json file to src/ then it will uninstall the module, but this is not where the composer.json file should be for 3rd modules.

Related issues:
https://github.com/magento/magento2/issues/7064
https://github.com/magento/magento2/issues/3290

Confirmed P3 ready for dev Reproduced on 2.1.x Reproduced on 2.2.x Reproduced on 2.3.x S3 help wanted

Most helpful comment

You can look in Magento\Framework\Module\Dir->getComposerJsonFiles() for the problem

All 3 comments

You can look in Magento\Framework\Module\Dir->getComposerJsonFiles() for the problem

the conflict comes from a method inside

Magento\Framework\Module\Dir\Reader.php

where

private function getFiles($filename, $subDir = '')

where

$file = $moduleSubDir . '/' . $filename;

is looking composer.json from path defined in composer.json itself as psr-4 (and not using the composer.json that was used to install the module )

@PascalBrouwers, thank you for your report.
We've created internal ticket(s) MAGETWO-81455 to track progress on the issue.

Was this page helpful?
0 / 5 - 0 ratings