I add js file in my module using the requirejs, but the requirejs can't load the file and i get this error:
require.js:1895 GET (my_ip)/magento2/pub/static/frontend/Magento/SaturTheme/it_IT/SliderHome/js/materialize.js
If I open this link I get this stacktrace error:
The "/var/www/html/magento2/" file doesn't exist or not a file
0 /var/www/html/magento2/vendor/magento/framework/Filesystem/Directory/Write.php(146): Magento\Framework\Filesystem\Directory\Write->assertIsFile(false)
1 /var/www/html/magento2/vendor/magento/framework/App/View/Asset/MaterializationStrategy/Symlink.php(30): Magento\Framework\Filesystem\Directory\Write->createSymlink(false, 'frontend/Magent...', Object(Magento\Framework\Filesystem\Directory\Write))
2 /var/www/html/magento2/vendor/magento/framework/App/View/Asset/Publisher.php(66): Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink->publishFile(Object(Magento\Framework\Filesystem\Directory\Write), Object(Magento\Framework\Filesystem\Directory\Write), false, 'frontend/Magent...')
3 /var/www/html/magento2/vendor/magento/framework/App/View/Asset/Publisher.php(50): Magento\Framework\App\View\Asset\Publisher->publishAsset(Object(Magento\Framework\View\Asset\File))
4 /var/www/html/magento2/vendor/magento/framework/App/StaticResource.php(109): Magento\Framework\App\View\Asset\Publisher->publish(Object(Magento\Framework\View\Asset\File))
5 /var/www/html/magento2/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\StaticResource->launch()
6 /var/www/html/magento2/pub/static.php(13): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\StaticResource))
7 {main}
I tried also to run this command, but nothing change:
php bin/magento --ansi setup:static-content:deploy it_IT
-
hey, can you give a bit more details please? 1. Could you share the folder structure of your module and the requirers-config.js file content? 2. How are you calling this js file. from a phtml?Asrar– Asrar2017年09月23日 16:24:03 +00:00Commented Sep 23, 2017 at 16:24
-
Please make sure that you follow all the required steps in this tutorial. devdocs.magento.com/videos/fundamentals/add-a-javascript-moduleThamira Madusanka– Thamira Madusanka2018年10月13日 11:18:56 +00:00Commented Oct 13, 2018 at 11:18
-
Have you added correct file path on requirejs file?Sweety Masmiya– Sweety Masmiya2022年01月16日 14:00:23 +00:00Commented Jan 16, 2022 at 14:00
3 Answers 3
you have to first delete pub/static folder all content.
Run Command
php bin/magento setup:static-content:deploy
Remove var folder from root.
Clear Browser cache.
Refresh page your js file is getting inside browser.
-
2you shouldn't remove .htaccess if you are using apacheMaciej Paprocki– Maciej Paprocki2017年01月13日 15:45:36 +00:00Commented Jan 13, 2017 at 15:45
-
No, the whole
pub/staticfolder should never be removed.Asrar– Asrar2017年09月23日 16:15:08 +00:00Commented Sep 23, 2017 at 16:15
Can you add your JS code (or at least the require JS dependency part) please? If your file name/paths are correct this should help:
- Delete
pub/static/frontend - Delete
pub/static/requirejs - Delete
var/view_preprocessed - Clear Magento caches
Do not delete the whole pub/static folder or you will run into problems.
Also if you are in developer mode (you should be for development) running the static-content deploy command is a waste of time as the files are symlinked anyway.
You need to make sure that your module's js file placed as per below location, If not then correct.
YourModule/view/frontend/web/js/materialize.js
-> After that you should run deploy command for your language (in case not in en_US)
php bin/magento setup:static-content:deploy it_IT
-> Flush cache and set proper permission to var and pub/static directory.