How to fix the «Undefined offset: 1 in vendor/magento/framework/App/Utility/Files.php on line 748» failure on a `js-translation.json` HTTP request?

bug
bug-fix
third-party-extension

(Dmitry Fedyuk) #1

Request URL: /static/adminhtml/Magento/backend/en_US/js-translation.json
Response:

Notice: Undefined offset: 1 in vendor/magento/framework/App/Utility/Files.php on line 748
#0 vendor/magento/framework/App/Utility/Files.php(748): Magento\Framework\App\ErrorHandler->handler(8, 'Undefined offse...', 'v...', 748, Array)
#1 vendor/magento/module-translation/Model/Js/DataProvider.php(94): Magento\Framework\App\Utility\Files->getJsFiles('base', 'Magento/backend')
#2 vendor/magento/module-translation/Model/Json/PreProcessor.php(86): Magento\Translation\Model\Js\DataProvider->getData('Magento/backend')
#3 vendor/magento/framework/View/Asset/PreProcessor/Pool.php(74): Magento\Translation\Model\Json\PreProcessor->process(Object(Magento\Framework\View\Asset\PreProcessor\Chain))
#4 vendor/magento/framework/View/Asset/Source.php(152): Magento\Framework\View\Asset\PreProcessor\Pool->process(Object(Magento\Framework\View\Asset\PreProcessor\Chain))
#5 vendor/magento/framework/View/Asset/Source.php(105): Magento\Framework\View\Asset\Source->preProcess(Object(Magento\Framework\View\Asset\File))
#6 var/generation/Magento/Framework/View/Asset/Source/Interceptor.php(24): Magento\Framework\View\Asset\Source->getFile(Object(Magento\Framework\View\Asset\File))
#7 vendor/magento/framework/View/Asset/File.php(150): Magento\Framework\View\Asset\Source\Interceptor->getFile(Object(Magento\Framework\View\Asset\File))
#8 vendor/magento/framework/App/StaticResource.php(97): Magento\Framework\View\Asset\File->getSourceFile()
#9 vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\StaticResource->launch()
#10 pub/static.php(13): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\StaticResource))
#11 {main}

The Google Chrome’s console displays this error as: «Uncaught SyntaxError: Unexpected token N in JSON at position 1»
01


(Dmitry Fedyuk) #2

The failure’s point is in the Magento\Framework\App\Utility\Files::getJsFiles() method:

The exact failure line:

02

So the problem is with the ShippingField module.


(Dmitry Fedyuk) #3

How to fix

Step 1

File: app/code/ShippingField/ShippingAddress/etc/module.xml

Replace the line:

<module name="ShippingField" setup_version="2.0.0" />

with the following one:

<module name="ShippingField" setup_version="2.0.0" />

Step 2

File: app/code/ShippingField/ShippingAddress/registration.php
Replace the block:

\Magento\Framework\Component\ComponentRegistrar::register(
  \Magento\Framework\Component\ComponentRegistrar::MODULE,
  'ShippingField',
  __DIR__
);

with the following one:

\Magento\Framework\Component\ComponentRegistrar::register(
	\Magento\Framework\Component\ComponentRegistrar::MODULE,
	'ShippingField_ShippingAddress',
	__DIR__
);

Step 3

Update the modules:

bin/magento setup:upgrade
rm -rf var/di var/generation generated/code && bin/magento setup:di:compile