I have upgraded Magento to 2.4.5 and deployed it to a new server.

When i browse site JS file is not loading, but css file is loading correctly

JS path is like this - https://test.com/jquery.js
CSS path is like this - https://test.com/static/version1687893220/_cache/merged/c2f02f3311375ce676a7b8fc512d783c.min.css

Also check with disable merge JS file but still same issue

Not sure why JS path is coming without static path

UPDATE system.log-

[2023-06-27T20:20:33.121142+00:00] report.CRITICAL: Invalid template file: '/var/www/test.com/var/view_preprocessed/pub/static/vendor/magento/module-theme/view/frontend/templates/page/js/require_js.phtml' in module: '' block's name: 'require.js'

Any idea?

  • plz share source code
    – channasmcs
    Jun 27 at 20:06
  • That i can not share for privacy purpose
    – Newbie
    Jun 27 at 20:23

2 Answers 2


we have to replace the code of file

vendor/magento/framework/view/element/template/file/validator.php with this.

protected function isPathInDirectories($path, $directories){

$realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path));
if (!is_array($directories)) {
    $directories = (array)$directories;

foreach ($directories as $directory) {
    if (0 === strpos($realPath, $directory)) {
        return true;
return false;


  • I already done that but this solution does not work for me
    – Newbie
    Jun 29 at 13:00

The error message in your system.log suggests that the template file require_js.phtml is invalid. This file is responsible for loading the JavaScript files that are used on your Magento website. If the file is invalid, then the JavaScript files will not be loaded.

There are a few possible reasons why the template file might be invalid. One possibility is that the file has been corrupted. Another possibility is that the file has been moved or deleted.

To troubleshoot this issue, you can try the following steps:

Check the permissions on the require_js.phtml file. Make sure that the file has the correct permissions so that it can be read by Magento.

Verify that the require_js.phtml file is located in the correct directory. The file should be located in the var/view_preprocessed/pub/static/vendor/magento/module-theme/view/frontend/templates/page/js/ directory.

If you have recently made any changes to the require_js.phtml file, try reverting those changes.

If you have tried all of these steps and you are still getting the same error, then you may need to contact Magento support for help.

In addition to the above, you may also want to check the following:

Make sure that your Magento installation is up to date

Clear the Magento cache.

Reindex the Magento search engine.

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.