1. Put your Custom JS file in the following directory
app/code/Vendor/YourModuleName/view/frontend/web/js/your_js_file_name.js
-> And your require-config.js file is in directory
var config = {
map: {
'*': {
myjs: 'Vendor_YourModuleName/js/your_js_file_name'
}
}
};
2. Delete Generated Files, Sessions & Caches:
YOUR_MAGENTO2_ROOT/var/cache/ ****DELETE ALL****
YOUR_MAGENTO2_ROOT/var/page_cache/ ****DELETE ALL****
YOUR_MAGENTO2_ROOT/var/session/ ****DELETE ALL****
YOUR_MAGENTO2_ROOT/var/view_preprocessed/ ****DELETE ALL****
-> Also, remove everything including old generated static files from below path except .htaccess:
YOUR_MAGENTO2_ROOT/pub/static/ ****DELETE ALL**** EXCEPT .HTACCESS
YOUR_MAGENTO2_ROOT/generated/code/ ****DELETE ALL****
YOUR_MAGENTO2_ROOT/generated/metadata/ ****DELETE ALL****
3. Open terminal and run following commands:
php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush
chmod -R 777 var/ pub/ generated/
chmod -R 777 var/* pub/* generated/*
Now check your modules js files are loaded under pub/static/