Skip to content

Module doesn’t work when placed in `app/code`

i’m editing a Magento 2 module. If i install the module via composer require, then run all the necessary commands, the module works.

If i manually copy the module files from vendor/{vendorname}/{modulename} to app/code/{vendorname}/{modulename}, then uninstall the vendor module via composer+all the necessary commands, then i enable the module present in app/code with the necessary commands, this is the result:
error in dashboard

And this is the resulting system.log:

[2022-10-21T14:57:47.998332+00:00] main.CRITICAL: Error: Class "MynamespaceHelperData" not found in /var/www/magento2-domain/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:121
Stack trace:
#0 /var/www/magento2-domain/vendor/magento/framework/ObjectManager/Factory/Compiled.php(108): MagentoFrameworkObjectManagerFactoryAbstractFactory->createObject()
#1 /var/www/magento2-domain/vendor/magento/framework/ObjectManager/Factory/Compiled.php(150): MagentoFrameworkObjectManagerFactoryCompiled->create()
#2 /var/www/magento2-domain/vendor/magento/framework/ObjectManager/Factory/Compiled.php(79): MagentoFrameworkObjectManagerFactoryCompiled->get()
#3 /var/www/magento2-domain/vendor/magento/framework/ObjectManager/ObjectManager.php(56): MagentoFrameworkObjectManagerFactoryCompiled->create()
#4 /var/www/magento2-domain/vendor/magento/framework/View/Element/BlockFactory.php(44): MagentoFrameworkObjectManagerObjectManager->create()
#5 /var/www/magento2-domain/vendor/magento/framework/View/Layout/Generator/Block.php(272): MagentoFrameworkViewElementBlockFactory->createBlock()
#6 /var/www/magento2-domain/vendor/magento/framework/View/Layout/Generator/Block.php(252): MagentoFrameworkViewLayoutGeneratorBlock->getBlockInstance()
#7 /var/www/magento2-domain/vendor/magento/framework/View/Layout/Generator/Block.php(229): MagentoFrameworkViewLayoutGeneratorBlock->createBlock()
#8 /var/www/magento2-domain/vendor/magento/framework/View/Layout/Generator/Block.php(134): MagentoFrameworkViewLayoutGeneratorBlock->generateBlock()
#9 /var/www/magento2-domain/vendor/magento/framework/View/Layout/GeneratorPool.php(93): MagentoFrameworkViewLayoutGeneratorBlock->process()
#10 /var/www/magento2-domain/vendor/magento/framework/View/Layout.php(365): MagentoFrameworkViewLayoutGeneratorPool->process()
#11 /var/www/magento2-domain/vendor/magento/framework/Interception/Interceptor.php(58): MagentoFrameworkViewLayout->generateElements()
#12 /var/www/magento2-domain/vendor/magento/framework/Interception/Interceptor.php(138): MagentoFrameworkViewLayoutInterceptor->___callParent()
#13 /var/www/magento2-domain/vendor/magento/framework/Interception/Interceptor.php(153): MagentoFrameworkViewLayoutInterceptor->MagentoFrameworkInterception{closure}()
#14 /var/www/magento2-domain/generated/code/Magento/Framework/View/Layout/Interceptor.php(32): MagentoFrameworkViewLayoutInterceptor->___callPlugins()
#15 /var/www/magento2-domain/vendor/magento/framework/View/Layout/Builder.php(129): MagentoFrameworkViewLayoutInterceptor->generateElements()
#16 /var/www/magento2-domain/vendor/magento/framework/View/Page/Builder.php(65): MagentoFrameworkViewLayoutBuilder->generateLayoutBlocks()
#17 /var/www/magento2-domain/vendor/magento/framework/View/Layout/Builder.php(65): MagentoFrameworkViewPageBuilder->generateLayoutBlocks()
#18 /var/www/magento2-domain/vendor/magento/framework/View/Layout.php(271): MagentoFrameworkViewLayoutBuilder->build()
#19 /var/www/magento2-domain/vendor/magento/framework/View/Layout.php(896): MagentoFrameworkViewLayout->build()
#20 /var/www/magento2-domain/vendor/magento/module-cms/Helper/Page.php(216): MagentoFrameworkViewLayout->getBlock()
#21 /var/www/magento2-domain/vendor/magento/module-cms/Controller/Index/Index.php(74): MagentoCmsHelperPage->prepareResultPage()
#22 /var/www/magento2-domain/vendor/magento/framework/Interception/Interceptor.php(58): MagentoCmsControllerIndexIndex->execute()
#23 /var/www/magento2-domain/vendor/magento/framework/Interception/Interceptor.php(138): MagentoCmsControllerIndexIndexInterceptor->___callParent()
#24 /var/www/magento2-domain/vendor/magento/framework/Interception/Interceptor.php(153): MagentoCmsControllerIndexIndexInterceptor->MagentoFrameworkInterception{closure}()
#25 /var/www/magento2-domain/generated/code/Magento/Cms/Controller/Index/Index/Interceptor.php(23): MagentoCmsControllerIndexIndexInterceptor->___callPlugins()
#26 /var/www/magento2-domain/vendor/magento/framework/App/Action/Action.php(111): MagentoCmsControllerIndexIndexInterceptor->execute()
#27 /var/www/magento2-domain/vendor/magento/framework/Interception/Interceptor.php(58): MagentoFrameworkAppActionAction->dispatch()
#28 /var/www/magento2-domain/vendor/magento/framework/Interception/Interceptor.php(138): MagentoCmsControllerIndexIndexInterceptor->___callParent()
#29 /var/www/magento2-domain/vendor/magento/framework/Interception/Interceptor.php(153): MagentoCmsControllerIndexIndexInterceptor->MagentoFrameworkInterception{closure}()
#30 /var/www/magento2-domain/generated/code/Magento/Cms/Controller/Index/Index/Interceptor.php(32): MagentoCmsControllerIndexIndexInterceptor->___callPlugins()
#31 /var/www/magento2-domain/vendor/magento/framework/App/FrontController.php(245): MagentoCmsControllerIndexIndexInterceptor->dispatch()
#32 /var/www/magento2-domain/vendor/magento/framework/App/FrontController.php(212): MagentoFrameworkAppFrontController->getActionResponse()
#33 /var/www/magento2-domain/vendor/magento/framework/App/FrontController.php(147): MagentoFrameworkAppFrontController->processRequest()
#34 /var/www/magento2-domain/vendor/magento/framework/Interception/Interceptor.php(58): MagentoFrameworkAppFrontController->dispatch()
#35 /var/www/magento2-domain/vendor/magento/framework/Interception/Interceptor.php(138): MagentoFrameworkAppFrontControllerInterceptor->___callParent()
#36 /var/www/magento2-domain/vendor/magento/module-store/App/FrontController/Plugin/RequestPreprocessor.php(99): MagentoFrameworkAppFrontControllerInterceptor->MagentoFrameworkInterception{closure}()
#37 /var/www/magento2-domain/vendor/magento/framework/Interception/Interceptor.php(135): MagentoStoreAppFrontControllerPluginRequestPreprocessor->aroundDispatch()
#38 /var/www/magento2-domain/vendor/magento/module-page-cache/Model/App/FrontController/BuiltinPlugin.php(75): MagentoFrameworkAppFrontControllerInterceptor->MagentoFrameworkInterception{closure}()
#39 /var/www/magento2-domain/vendor/magento/framework/Interception/Interceptor.php(135): MagentoPageCacheModelAppFrontControllerBuiltinPlugin->aroundDispatch()
#40 /var/www/magento2-domain/vendor/magento/framework/Interception/Interceptor.php(153): MagentoFrameworkAppFrontControllerInterceptor->MagentoFrameworkInterception{closure}()
#41 /var/www/magento2-domain/generated/code/Magento/Framework/App/FrontController/Interceptor.php(23): MagentoFrameworkAppFrontControllerInterceptor->___callPlugins()
#42 /var/www/magento2-domain/vendor/magento/framework/App/Http.php(116): MagentoFrameworkAppFrontControllerInterceptor->dispatch()
#43 /var/www/magento2-domain/vendor/magento/framework/App/Bootstrap.php(264): MagentoFrameworkAppHttp->launch()
#44 /var/www/magento2-domain/pub/index.php(30): MagentoFrameworkAppBootstrap->run()
#45 {main} [] []

From this log it seems that magento cannot find one of my module’s classes, as if the class has not been autoloaded.

So my question is:
How is it possible that the EXACT same module works when placed in the vendor folder via composer, but doesn’t work when manually placed under app/code ??

The module is evidently working when placed in vendor, hence the code is correct.

Isn’t app/code meant to be used for the live development of modules?? Am i missing something?


Please note: after i moved the module to app/code i ran the following commands:

  composer install
  composer dump-autoload
  bin/magento module:status
  bin/magento module:enable Companyname_Modulename --clear-static-content
  bin/magento setup:upgrade
  bin/magento setup:di:compile