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.
Open up
app/etc/di.xml
and find thevirtualType name="developerMaterialization"
section. In that section you'll find an itemname="view_preprocessed"
that needs to be modified or deleted. You can modify it by changing the contents fromMagento\Framework\App\View\Asset\MaterializationStrategy\Symlink
toMagento\Framework\App\View\Asset\MaterializationStrategy\Copy
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,
- 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.
Delete all folders in pub/static. Don't delete .htaccess and other files.
Run XAMPP as an administrator. Run the command line as an administrator. Run
grunt exec:<theme name>
.
You will see it is running fine.
Then you can run grunt less:<theme name>
Finally, you can run grunt watch
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.