How to Fix 404 Error for Scripts and CSS in Magento 2
If you’ve got Magento 2 from
First of all, check whether the Apache rewrite engine is on or not. If it is disabled, turn the engine on. If CSS and JS files are not loading, try to access them directly from the browser. The following exception is displayed?
1 2 3 4 5 6 7 8 9 |
Cannot create a symlink for "D:/xampp/htdocs/magento2/lib/web/mage/calendar.css" and place it to "D:/xampp/htdocs/magento2/pub/static/frontend/Magento/blank/en_US/mage/calendar.css" Warning!symlink(): Cannot create symlink, error code(1314) #0 D:\xampp\htdocs\magento2\lib\internal\Magento\Framework\Filesystem\Directory\Write.php(155): Magento\Framework\Filesystem\Driver\File->symlink('D:/xampp/htdocs...', 'D:/xampp/htdocs...', Object(Magento\Framework\Filesystem\Driver\File)) #1 D:\xampp\htdocs\magento2\lib\internal\Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink.php(30): Magento\Framework\Filesystem\Directory\Write->createSymlink('lib/web/mage/ca...', 'frontend/Magent...', Object(Magento\Framework\Filesystem\Directory\Write)) #2 D:\xampp\htdocs\magento2\lib\internal\Magento\Framework\App\View\Asset\Publisher.php(65): Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink->publishFile(Object(Magento\Framework\Filesystem\Directory\Write), Object(Magento\Framework\Filesystem\Directory\Write), 'lib/web/mage/ca...', 'frontend/Magent...') #3 D:\xampp\htdocs\magento2\lib\internal\Magento\Framework\App\View\Asset\Publisher.php(49): Magento\Framework\App\View\Asset\Publisher->publishAsset(Object(Magento\Framework\View\Asset\File)) #4 D:\xampp\htdocs\magento2\lib\internal\Magento\Framework\App\StaticResource.php(118): Magento\Framework\App\View\Asset\Publisher->publish(Object(Magento\Framework\View\Asset\File)) #5 D:\xampp\htdocs\magento2\lib\internal\Magento\Framework\App\Bootstrap.php(245): Magento\Framework\App\StaticResource->launch() #6 D:\xampp\htdocs\magento2\pub\static.php(13): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\StaticResource)) #7 {main} |
Don’t panic! The solution to your problem is described below! The nature of Magento 2 forces it to create symlinks for some static resources when not in the production mode. You just need to change that behaviour. Follow the two simple steps described below:
- In app/etc/di.xml, find the virtualType name=”developerMaterialization” section and its item called name=”view_preprocessed”. Modify or delete it depending on your needs. To change the content of the item replace Symlink with Copy in Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink.
- To get rid of any existing symlinks, you need to delete the files. Go to pub/static and cleanse it but be careful: the .htaccess file is situated there as well – don’t delete it!
Now, the symlink error is solved. We hope this article was useful. It is based on the