Magento 2 404 error for scripts and css

When not in production mode Magento 2 will try to create symlinks for some static resources. You can change that behavior by doing the following.

  1. Open up app/etc/di.xml and find the virtualType name="developerMaterialization" section. In that section you'll find an item name="view_preprocessed" that needs to be modified or deleted. You can modify it by changing the contents from Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink to Magento\Framework\App\View\Asset\MaterializationStrategy\Copy

  2. Delete the files under pub/static to get rid of any existing symlinks. You may want to be careful not to delete the .htaccess file.

This should solve your error with the symlink.


I faced this problem and try to figure out. I agree with Chris O'Toole. I will add an extra step. My steps are,

  1. Open app/etc/di.xml and search Symlink. Check it is in the following section.
<virtualType name="developerMaterialization" type="Magento\Framework\App\View\Asset\MaterializationStrategy\Factory">
                <arguments>
                    <argument name="strategiesList" xsi:type="array">
                        <item name="view_preprocessed" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Copy</item>
                        <item name="default" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Copy</item>
                    </argument>
                </arguments>
            </virtualType>

Replace Symlink with Copy word. Save.

  1. Delete all folders in pub/static. Don't delete .htaccess and other files.

  2. Run XAMPP as an administrator. Run the command line as an administrator. Run grunt exec:<theme name>.

enter image description here

You will see it is running fine.

Then you can run grunt less:<theme name>

enter image description here

Finally, you can run grunt watch

enter image description here

When you do any changes in fewer files(_theme.less or _extend.less) it will automatically create style-l and style-m CSS files in pub/static folder.

I'm running Magento 2.1 in windows 10.


Remember to update file permissions after Magento creates these new static files. They are not owned by www-data, so they will give 404.