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 · 35 comments

Comments

@zucler
Copy link

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

This comment has been minimized.

Copy link

commented Dec 19, 2016

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link

commented Dec 21, 2016

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link

commented Dec 22, 2016

@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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link

commented Dec 23, 2016

@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

This comment has been minimized.

Copy link
Contributor

commented Dec 26, 2016

@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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Author

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

commented Dec 29, 2016

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

@WaeCo

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

commented Feb 3, 2017

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

This comment has been minimized.

Copy link
Contributor

commented Feb 16, 2017

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

@hrushikesh07

This comment has been minimized.

Copy link

commented Apr 11, 2017

error

How to remove version from link .

@slimzc

This comment has been minimized.

Copy link

commented Apr 11, 2017

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);

@korostii

This comment has been minimized.

Copy link

commented Apr 12, 2017

You can disable option in your admin

Have you even tried saving a config value in admin while not having JS operational? =D
The SQL workaround was already mentioned above. Please read the whole thread first (before rushing to comment). Besides, it must be noted that saving that option simply disables the feature and doesn't fix it.

@nafisakanwal

This comment has been minimized.

Copy link

commented May 8, 2017

I am using Fedora 25 , having
Apache/2.4.25 (Fedora)
PHP Version 7.0.18
MySql 5.7.18

I have just installed magneto 2.1.6 , after successfull setup run, its getting css and js files not found issue and they are loading from pub/static//version1494143163/frontend/Magento/luma/en_US/css/styles-m.css
version1494143163 is not even existed.
Beside this the admin url is also not accessible .

Can anyone can help me

@mfang0126

This comment has been minimized.

Copy link

commented May 13, 2017

I got the same issue, which like nafisakanwal

@dnadle

This comment has been minimized.

Copy link

commented May 13, 2017

It looks to me like "sign static files" is inserting "versionNNNNNNNNN" into the URLs, but setup:static-content-deploy is not placing the content in that path.

@timri

This comment has been minimized.

Copy link

commented Jun 7, 2017

That is as expected/not the problem: the file ".htaccess" in pub/static contains this rewrite-rule:

    # Remove signature of the static files that is used to overcome the browser cache
    RewriteRule ^version.+?/(.+)$ $1 [L]

I.e. the version?????-part is taken out of the url before hitting the filesystem.

However, is the url reachable if you remove the version????-part?
I have this problem, too, but it seems only with module Magento_ConfigurableProduct
Both "http://myserver/shop/static/version1496826764/adminhtml/Magento/backend/de_DE/Magento_ConfigurableProduct/js/components/custom-options-warning.js" and "http://myserver/shop/static/adminhtml/Magento/backend/de_DE/Magento_ConfigurableProduct/js/components/custom-options-warning.js" return:
Unable to resolve the source file for 'adminhtml/Magento/backend/de_DE/Magento_ConfigurableProduct/js/components/custom-options-warning.js'

dev@www:~/magento$ ls -l vendor/magento/module-configurable-product/view/base/adminhtml/web/js/components/
total 48
-rw-rw-rw- 1 dev dev  9463 Mar 28 15:26 associated-product-insert-listing.js
-rw-rw-rw- 1 dev dev  1777 Mar 28 15:26 container-configurable-handler.js
-rw-rw-rw- 1 dev dev  1970 Mar 28 15:26 custom-options-price-type.js
-rw-rw-rw- 1 dev dev   662 Mar 28 15:26 custom-options-warning.js
-rw-rw-rw- 1 dev dev 15920 Mar 28 15:26 dynamic-rows-configurable.js
-rw-rw-rw- 1 dev dev  2325 Mar 28 15:26 file-uploader.js
-rw-rw-rw- 1 dev dev   883 Mar 28 15:26 modal-configurable.js
dev@www:~/magento$ curl -I http://myserver/shop/static/adminhtml/Magento/backend/de_DE/Magento_Catalog/catalog/product.js
HTTP/1.1 200 OK
Date: Wed, 07 Jun 2017 10:06:00 GMT
Server: Apache/2.4.10 (Debian)
Last-Modified: Tue, 28 Mar 2017 13:25:54 GMT
ETag: "8db-54bca66385c80"
Accept-Ranges: bytes
Content-Length: 2267
Vary: Accept-Encoding
Content-Type: application/javascript

dev@www:~/magento$ curl -I http://myserver/shop/static/adminhtml/Magento/backend/de_DE/Magento_ConfigurableProduct/js/components/custom-options-warning.js
HTTP/1.1 404 Not Found
Date: Wed, 07 Jun 2017 10:06:16 GMT
Server: Apache/2.4.10 (Debian)
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Content-Type: text/plain;charset=UTF-8

dev@www:~/magento$ curl http://myserver/shop/static/adminhtml/Magento/backend/de_DE/Magento_ConfigurableProduct/js/components/custom-options-warning.js
Unable to resolve the source file for 'adminhtml/Magento/backend/de_DE/Magento_ConfigurableProduct/js/components/custom-options-warning.js'
#0 /home/dev/magento/vendor/magento/framework/App/StaticResource.php(97): Magento\Framework\View\Asset\File->getSourceFile()
#1 /home/dev/magento/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\StaticResource->launch()
#2 /home/dev/magento/pub/static.php(13): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\StaticResource))
#3 {main}

This is a Magento-CE 2.1.6

@timri

This comment has been minimized.

Copy link

commented Jun 9, 2017

Ok, my problem is solved now (but has nothing to do with this bug):
Someone accidentally moved the folder vendor/magento/module-configurable-product/view/adminhtml inside vendor/magento/module-configurable-product/view/base

@mengbo123456

This comment has been minimized.

Copy link

commented Jul 3, 2017

# now i know why can't linking style ,but i don't know why this?
because install path no version1499055289 folder ,and i add it style work
qq 20170703141604
qq 20170703141841
qq 20170703142510
but i don't know why it can't add version1499055289 folder itself in During the installation process

@ignat980

This comment has been minimized.

Copy link

commented Aug 16, 2017

Hey everyone, I think I got a fix for you:

I had this same issue on a new magento install. There are two issues here at play: Malformed apache configuration and non-deployed static content (at least for me). It is not mentioned at http://devdocs.magento.com/guides/v2.1/install-gde/install/web/install-web_6-install.html, but you need to run the command bin/magento setup:static-content:deploy for pub/static/ to be populated with the static content. (Huge thanks to Anil Suthar (Stack Overflow))

I wouldn't recommend changing permissions to 777, what I did was do it as single user setup and set permissions to web server user, default is www-data:chown -R www-data:www-data /. (Note: this StackOverflow post has some good points about permissions)

Lastly, what's up with the folder versionXXXXXXXXXX? Well, if you look at .htaccess in pub/static/ you'll see two Rewrite Rules:

RewriteRule ^version.+?/(.+)$ $1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule .* ../static.php?resource=$0 [L]

(The second one triggers if the requested resource is not found)

The first rule removes the version folder in the request and serves instead frontend/ or adminhtml/ the resource asks for.

Check what apache2.conf says in /etc/apache2/ (if Ubuntu), it's possible that /var/www/ directory has AllowOverride None set. It should be AllowOverride All, so that .htaccess files can override directives.

All of that fixed it for me, I hope this helps anyone else!

........
Sigh, Post Factum I've found out that this is problem is mentioned in the verify installation page. Here's the link that basically mimics what I wrote here: http://devdocs.magento.com/guides/v2.1/install-gde/trouble/tshoot_no-styles.html

@ozziel

This comment has been minimized.

Copy link

commented Oct 7, 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!

@magento-engcom-team

This comment has been minimized.

Copy link
Contributor

commented Nov 24, 2017

Hi @zucler
Could you please let us know if the issue is still actual? Thank you

@wd7080

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Contributor

commented Dec 7, 2017

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

This comment has been minimized.

Copy link
Contributor

commented Dec 7, 2017

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

@bdt195

This comment has been minimized.

Copy link

commented Mar 15, 2018

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

@bruno-serfe

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

commented Apr 2, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.