Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Magento2 cannot resolve path to pub/static JS files #7869

Closed
zucler opened this issue Dec 19, 2016 · 52 comments
Closed

Magento2 cannot resolve path to pub/static JS files #7869

zucler opened this issue Dec 19, 2016 · 52 comments
Labels
bug report Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Progress: needs update

Comments

@zucler
Copy link

zucler commented Dec 19, 2016

Preconditions

  1. Magento ver. 2.1.3
  2. PHP 7.0
  3. MySQL 5.6

All of the above running in docker containers. Files are sync'ed using docker-sync utility, but I've also tried mounting volumes directly from my local host drive and it did not help.

I've confirmed that PHP is running as www-data user and that all project files have read & write permissions on every file and directory within the project.

I have previously tried deleting all manual content and running setup:static-content:deploy. Static files were re-created, but it didn't help me to solve my problem.

Lastly, I've troubleshooted the code as far as I could and got to the point where in

vendor/magento/framework/View/Design/FileResolution/Fallback/Resolver/Simple.php file

protected function resolveFile(RuleInterface $fallbackRule, $file, array $params = [])
    {
        //->getPatternDirs return Array ( [0] => /var/www/html/lib/web )
        // given that nginx doc root path is /var/www/html
        foreach ($fallbackRule->getPatternDirs($params) as $dir) {
            $path = "{$dir}/{$file}";
            $dirRead = $this->readFactory->create($dir);
            if ($dirRead->isExist($file) && $this->checkFilePathAccess($file, $path)) {
                return $path;
            }
        }
        return false;
    }

Error details:

Unable to resolve the source file for '_requirejs/adminhtml/Magento/backend/en_US/requirejs-config.js'
#0 /var/www/html/vendor/magento/framework/App/StaticResource.php(97): Magento\Framework\View\Asset\File->getSourceFile()
#1 /var/www/html/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\StaticResource->launch()
#2 /var/www/html/pub/static.php(13): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\StaticResource))
#3 {main}

Also, I have confirmed that these files actually exist, but Magento is unable to work out their paths correctly.

Steps to reproduce

  1. Open management page or default Luma page

Expected result

  1. All files are loaded and all Javascript on the page is working

Actual result

  1. The files below can not be loaded, thus no JS is working on the page
@swieczorek
Copy link

I noticed the same issue. After installing a blank Magento 2.1.3 you are not able to use the backend because of the missing files.

@careys7
Copy link
Member

careys7 commented Dec 20, 2016

I have the same issue after upgrading from Magento 2.1.2 (Enterprise) to Magento 2.1.3 using a composer upgrade.

I think it's due to changes made in static files - see release notes:

  • We’ve corrected a problem with _requirejs asset retrieval via static.php in static content versioning.
  • Versioning of static files (including CSS, JS, font, and image files) is now enabled by default.

I am using example nginx configuration, and have tried switching to both developer and production modes. Request reaches static.php correctly which then returns a 404 header to nginx. The referenced files exist on disk and I have verified file permissions.

I used the following workaround to disable static file signing, which has corrected the 404 for me:

INSERT INTO `core_config_data` (`scope`, `scope_id`, `path`, `value`) VALUES ('default', 0, 'dev/static/sign', '0');

You will need to clear cache after this, and also check for any entries with the same config path if you have previously modified this setting.

This isn't a very good workaround as it would break cache-busting when using Varnish or any CDNs etc, but at least assets do not 404.

@jmonschke
Copy link

I ran into the same issue with the upgrade, and the solution is updating the nginx or apache configuration to fix the rewriting issues. The /static/ section of Nginx should be as follows to be able to get it working properly.

 location /static/ {
    if ($MAGE_MODE = "production") {
      expires max;
    }

    # Remove signature of the static files that is used to overcome the browser cache
    location ~ ^/static/version {
      rewrite ^/static/(version\d*/)?(.*)$ /static/$2 last;
    }

    location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
      add_header Cache-Control "public";
      add_header X-Frame-Options "SAMEORIGIN";
      expires +1y;

      if (!-f $request_filename) {
        rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
      }
    }

    location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
      add_header Cache-Control "no-store";
      add_header X-Frame-Options "SAMEORIGIN";
      expires off;

      if (!-f $request_filename) {
         rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
      }
    }

    if (!-f $request_filename) {
      rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
    }

    add_header X-Frame-Options "SAMEORIGIN";
  }

@careys7
Copy link
Member

careys7 commented Dec 21, 2016

Thanks @jmonschke - my nginx file was missing the fix added in #2323. Adding this works for me.

It seems that the other version regexes are redundant (or were broken prior to #2323). I think these should just be removed (see #7921).

@adifucan adifucan self-assigned this Dec 22, 2016
@adifucan
Copy link
Contributor

adifucan commented Dec 22, 2016

@zucler @careysizer @swieczorek @jmonschke Guys, can you provide us with more information about your configuration to reproduce this issue.

  • Are you all encountering this issue after update from previous version (what version?) to 2.1.3?
  • Are you all using Nginx?
  • Are you all using docker?
  • What edition of Magento do you use: CE or EE?
  • What permissions and ownership do you have for Magento webroot?
    I tested it with the following permissions: http://magento.stackexchange.com/a/95033

Firstly, I installed Magento CE 2.1.3 via composer on docker contains: 1 with nginx & php, 1 with mysql in default and developer mode and it works.
Secondly, in installed Magento CE 2.1.3 on vagrant with nginx/1.10.2, php 7.0.14, mysql 5.6 in default, developer and production modes and it works fine.
Thirdly, I installed Magento CE 2.1.2 on vagrant with nginx/1.10.2, php 7.0.14, mysql 5.6 in default& developer modes and updated via composer to Magento CE 2.1.3 and it worked.
But after I switched to production mode after upgrade from previous version to 2.1.3 I got an exception:

php bin/magento setup:static-content:deploy
Requested languages: en_US
Requested areas: frontend, adminhtml
Requested themes: Magento/blank, Magento/luma, Magento/backend
=== frontend -> Magento/blank -> en_US ===
=== frontend -> Magento/luma -> en_US ===
=== adminhtml -> Magento/backend -> en_US ===
.
                                                                                                                                                       
  [Magento\Framework\Exception\FileSystemException]                                                                                                    
  The path "_requirejs/adminhtml/Magento/backend/en_US/requirejs-config.js:///var/www/magento/pub/static/var/www/magento/pub/static/" is not writable

Is this it?

@jmonschke
Copy link

@adifucan That is not the issues that I was seeing at all. The issue was that the files were there and being generated, but when the browser made the request for them, the web server was unable to do anything about it.

There are new nginx.conf.sample and .htaccess.sample files in the repository that you should pay attention to when running this particular upgrade.

@adifucan adifucan removed their assignment Dec 22, 2016
@adifucan
Copy link
Contributor

adifucan commented Dec 23, 2016

@jmonschke Sorry for inconvenience but can you provide us with exact steps to reproduce this bug?

  • Do you encounter this issue after update from previous version (what version?) to 2.1.3?
  • Do you use Nginx?
  • Do you use docker?
  • What edition of Magento do you use: CE or EE?
  • What permissions and ownership do you have for Magento webroot?
  • What mode are you in?
  • Do you have root $MAGE_ROOT/pub; in nginx.conf.sample file?
    I'm using the latest nginx.conf.sample and .htaccess.sample files.
    Thanks!

@jmonschke
Copy link

@adifucan I saw this when upgrading from 2.1.2 to 2.1.3.

I am using nginx and docker and EE.

I'm in developer mode, and have a special www-data user and group as ownership of the magento files.

@adifucan
Copy link
Contributor

@jmonschke I have just installed Magento EE 2.1.2 on Vagrant with composer and nginx as a web server. I set permissions and ownership like here: http://devdocs.magento.com/guides/v2.1/install-gde/prereq/file-system-perms.html
I'm in developer mode.
Then I updated Magento to 2.1.3 with composer update like here: http://devdocs.magento.com/guides/v2.0/comp-mgr/cli/cli-upgrade.html
And Magento (backend/frontend works) fine.

So I guess probably it's the issue with docker?

But I have one more question: do you set the Magento root directory to /pub or not?
I tested it WITHOUT pub directory root. So may be that's the reason why I cannot reproduce it?

Thanks!

@giacmir
Copy link
Member

giacmir commented Dec 27, 2016

I have this issue too in developer mode and Magento 2.1.3. For me is related to static files versioning that is defaulted to "on" in Magento 2.1.3. If I change it back to off (from database since admin interface is not working anymore) then it goes well.

@zucler
Copy link
Author

zucler commented Dec 27, 2016

@adifucan to answer you questions:

Do you encounter this issue after update from previous version (what version?) to 2.1.3?
No, this is my first time with Magento, I have just installed a clean version.

Do you use Nginx?
Yes, I do

Do you use docker?
Yes, I followed this guide: http://andykdocs.de/development/Docker/Dockerize-Magento-2-on-Mac-OS

What edition of Magento do you use: CE or EE?
Community Edition

What permissions and ownership do you have for Magento webroot?
www-data, all files user and group are set to www-data, permissions are 775

What mode are you in?
Development mode

Do you have root $MAGE_ROOT/pub; in nginx.conf.sample file?
Yes

I haven't tried @jmonschke workaround yet, but I'm definitely running the latest nginx config, so @careysizer case doesn't apply to my setup.

Thanks!

P.S. I traced my problem to the fact that it gets to static.php script that is then failing to work out a correct path. So, I don't think it is related to permissions. I've also tried changing all files permissions within the container to 777 and it didn't help. Files do exist on the disk though.

@slimzc
Copy link

slimzc commented Dec 28, 2016

Hi, I have a similar problem but I see the file are in _pub/static/requirejs/adminhtml/Magento/backend/es_CL/ because i change the default language using setup:install --language=es_CL Any idea?

@spyrule
Copy link

spyrule commented Dec 29, 2016

@slimzc - Its all the same problem, regardless of what language you have chosen (from what I understand).

@Niels-Be
Copy link

Niels-Be commented Dec 29, 2016

I encounterd this problem after installing a custum language packege.
I had a fresh 2.1.3 production installation from tar ball using Apache and everything was working fine. After running bin/magento setup:di:compile require js was not able to find the files any more.
My guess is that the fresh installed version containes some uncompiled changes and thats why you can't reproduce it in a fresh installation. Can someone confirm this?

Additionally the database fix did not work for me.

@AgenturSchroeder
Copy link

Can confirm the same problem. I installed a fresh version 2.1.3 with sample data and run in to the same error with the missed links/files. Can't use the backend.

@jalogut
Copy link
Contributor

jalogut commented Feb 16, 2017

I can confirm that adding the rewrite Nginx configuration fixes the issue. Thanks @careys7 and @jmonschke

@hrushikesh07
Copy link

error

How to remove version from link .

@wd7080
Copy link

wd7080 commented Nov 30, 2017

I can see this issue is still actual from errors reported on the google search consol under crawl errors. Have a look at the below:
google webmaster

@magento-engcom-team
Copy link
Contributor

Hi @wd7080
Your issue don't related with issue by first reporter.
If you have an issue, you should create new ticket and describe steps to reproduce.

@magento-engcom-team
Copy link
Contributor

@zucler, we are closing this issue due to inactivity. If you'd like to update it, please reopen the issue.

@bdt195
Copy link

bdt195 commented Mar 15, 2018

just run a2enmod rewrite (on apache server). It's working for me

@ghost
Copy link

ghost commented Apr 6, 2018

I've exactly the same issue, I've tried the suggested by @ignat980 without success. Also de @careys7 suggested solution didn't work for me neither.

@mehreeizad1
Copy link

mehreeizad1 commented May 16, 2018

This is work for me.
I Just back .htaccess file to the folder pub/static/
Thanks ozziel


ozziel commented on 7 Oct 2017

I must have erased the .htaccess file in /pub/static by accident...I've been looking for the answer for 3 hours! So if you're missing your theme on your admin and your store... check for a versionXXXXXXXXXX in the firebug console. if so recreate the .htaccess file with the above 4 lines in it. Thank you so much!

@JORDYSCHEMPARATHY
Copy link

I have the same issue after upgrading from Magento 2.1.2 (Enterprise) to Magento 2.1.3 using a composer upgrade.

I think it's due to changes made in static files - see release notes:

  • We’ve corrected a problem with _requirejs asset retrieval via static.php in static content versioning.
  • Versioning of static files (including CSS, JS, font, and image files) is now enabled by default.

I am using example nginx configuration, and have tried switching to both developer and production modes. Request reaches static.php correctly which then returns a 404 header to nginx. The referenced files exist on disk and I have verified file permissions.

I used the following workaround to disable static file signing, which has corrected the 404 for me:

INSERT INTO `core_config_data` (`scope`, `scope_id`, `path`, `value`) VALUES ('default', 0, 'dev/static/sign', '0');

You will need to clear cache after this, and also check for any entries with the same config path if you have previously modified this setting.

This isn't a very good workaround as it would break cache-busting when using Varnish or any CDNs etc, but at least assets do not 404.

Thanks @careys7 : This solution worked.

@masmaleki
Copy link

I have the same issue after upgrading from Magento 2.1.2 (Enterprise) to Magento 2.1.3 using a composer upgrade.
I think it's due to changes made in static files - see release notes:

  • We’ve corrected a problem with _requirejs asset retrieval via static.php in static content versioning.
  • Versioning of static files (including CSS, JS, font, and image files) is now enabled by default.

I am using example nginx configuration, and have tried switching to both developer and production modes. Request reaches static.php correctly which then returns a 404 header to nginx. The referenced files exist on disk and I have verified file permissions.
I used the following workaround to disable static file signing, which has corrected the 404 for me:

INSERT INTO `core_config_data` (`scope`, `scope_id`, `path`, `value`) VALUES ('default', 0, 'dev/static/sign', '0');

You will need to clear cache after this, and also check for any entries with the same config path if you have previously modified this setting.
This isn't a very good workaround as it would break cache-busting when using Varnish or any CDNs etc, but at least assets do not 404.

Thanks @careys7 : This solution worked.

Thanks @careys7 : This solution worked for me Also

@masmaleki
Copy link

You can disable option in your admin
Stores>Configuration>Advanced>Developer>Sign Static Files (dev_static_sign)

Or simply insert this row in your core_config_data table
insert core_config_data (config_id, scope, scope_id, path, value) values (null, 'default', 0, 'dev/static/sign', 0);

Thanks, Worked for me on Magento 2.3.3 and Wamp Server On Wndows

@masmaleki
Copy link

I have the same issue after upgrading from Magento 2.1.2 (Enterprise) to Magento 2.1.3 using a composer upgrade.

I think it's due to changes made in static files - see release notes:

  • We’ve corrected a problem with _requirejs asset retrieval via static.php in static content versioning.
  • Versioning of static files (including CSS, JS, font, and image files) is now enabled by default.

I am using example nginx configuration, and have tried switching to both developer and production modes. Request reaches static.php correctly which then returns a 404 header to nginx. The referenced files exist on disk and I have verified file permissions.

I used the following workaround to disable static file signing, which has corrected the 404 for me:

INSERT INTO `core_config_data` (`scope`, `scope_id`, `path`, `value`) VALUES ('default', 0, 'dev/static/sign', '0');

You will need to clear cache after this, and also check for any entries with the same config path if you have previously modified this setting.

This isn't a very good workaround as it would break cache-busting when using Varnish or any CDNs etc, but at least assets do not 404.

Thanks, Worked for me on Magento 2.3.3 and Wamp Server On Wndows

@diamondavocado
Copy link

diamondavocado commented Mar 9, 2020

This is still an issue on Magento 2.3.4.

This happens with a brand new, fresh M2 install.

I'm using:

  • centos-release-7-7.1908.0.el7.centos.x86_64
  • httpd 2.4.41
  • php 7.2.27 (fpm-fcgi)

Permissions all correct, rewrites enabled etc.

Disabling static content signing is not a real solution because it will affect caching etc.

I can't believe this issue has been closed.

@magento-engcom-team Please re-open this issue.

@jackrevate
Copy link

Agreed, having it on 2.3.4 also...

@Javiercc78
Copy link

He tratado todas las soluciones aportadas por varios sitios sin solución. Finalmente el problema estaba en los archivos de sesión.
Por un error en mi servidor plesk modifique temporalmente el directorio de almacenamiento de sesión en env.php al directorio var/sessions en mi raid de magento.
Modifique los permisos en mi servidor para el almacenamiento de sesion y restarure env.php para almacenar nuevamente las sesiones en el directorio de mi servidor e inmediatamente se corrigio el problema. Espero le sirva a alguien o de luz a algun problema similar.

@dndeus
Copy link

dndeus commented Jun 6, 2020

I'm sorry but that's pathetic... M2 v2.3.5

@psolovyov
Copy link

Still happening on 2.3.5 with nginx.conf.sample

@BuysTooMuch
Copy link

BuysTooMuch commented Oct 12, 2020

Seeing the same on 2.4.0 Open Source/CE - site running fine for weeks following initial installation, no problems till the day I tried static deploy / di compile etc. After first attempt the admin went dead, google TFA disappeared during login, etc. Require.js failing to load at the "version" URL despite Apache setup allowing overrides, no missing htaccess file, permissions set fine, ownership fine, etc etc etc... I also tried changing app/etc/di.xml MaterializationStrategy to "copy" and back to "Symlink" with no difference either way.

@diegoot-dev
Copy link

Saem problem version 2.4.0

@s1mplex1337
Copy link

Having the same issue on a fresh Magento 2.4.1 installation. In developer mode I get 403 access denied on some .js and .css files. Interestingly enough those files are just symlinked. When I switch to production mode everything is fine (theres some bugs in the initial files though which wont let you compile - some commas at the wrong places in the code). Anyone ever solved this?

@angelflo
Copy link

having same problem after upgrading to magento 2.4.1

@s1mplex1337
Copy link

s1mplex1337 commented Oct 19, 2020

For some reason, and I don't really know why exactly, but check your apache settings and disable "Restrict the ability to follow symbolic links". I dont know why this suddenly seems to be a problem on Magento 2.4+ (I'm running other Magento 2.3.x installations on the same server without any issues). But disabling this worked out for me.

You can also try this, to actually get rid of Magento using symlinks: https://community.magento.com/t5/Can-Magento-do/How-to-use-Magento-2-with-no-symlinks-anywhere/td-p/48402

@angelflo
Copy link

I use nginx ... does someone have a fix for this ?

@s1mplex1337
Copy link

I use nginx ... does someone have a fix for this ?

I'm not sure about that, I used nginx as a proxy with apache and not pure nginx. I would recommend you to do so aswell. However you might try to make Magento not use symlinks with this:

  1. Open app/etc/di.xml
  2. Replace all Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink occurrences with Magento\Framework\App\View\Asset\MaterializationStrategy\Copy

Found this here: https://community.magento.com/t5/Can-Magento-do/How-to-use-Magento-2-with-no-symlinks-anywhere/td-p/48402

It might help if you have the symlink issue.

@Luc4G3r
Copy link

Luc4G3r commented Nov 25, 2021

Setting dev/static/sign to 0 is NOT a proper solution to this. It will make the browser caches of visitors assume, that they have your script and other static files stored. This can lead to problems, when you update and rebuild your static files.

magento-devops-reposync-svc pushed a commit that referenced this issue Sep 9, 2022
…92022

[2.4.6]_Hammer_community_Backlog_06092022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Progress: needs update
Projects
None yet
Development

No branches or pull requests