1

I recently migrated a shop from a server to another.

The admin site works fine.

The javascript of the shop itself is broken, and the console filled with these error messages that I previously did not have:

Uncaught Error: Script error for "domReady", needed by: domReady!_unnormalized2, domReady!_unnormalized4
https://requirejs.org/docs/errors.html#scripterror
    at makeError (require.js:168:17)
    at HTMLScriptElement.onScriptError (require.js:1738:36)

Uncaught Error: Script error for "text", needed by: text!js-translation.json_unnormalized3
https://requirejs.org/docs/errors.html#scripterror
    at makeError (require.js:168:17)
    at HTMLScriptElement.onScriptError (require.js:1738:36)

Uncaught Error: Script error for "js-cookie/js.cookie", needed by: js-cookie/cookie-wrapper
https://requirejs.org/docs/errors.html#scripterror
    at makeError (require.js:168:17)
    at HTMLScriptElement.onScriptError (require.js:1738:36)

Uncaught Error: Script error for "Magento_Ui/js/core/renderer/layout"
https://requirejs.org/docs/errors.html#scripterror
    at makeError (require.js:168:17)
    at HTMLScriptElement.onScriptError (require.js:1738:36)

And a lot more.

When I see the source files loaded, some JS is actually there such as jQuery...

There is no kind of error when compiling, deploying, updating modules or using any command really.

Most .js errors seems to be coming from this theme:

https://www.weltpixel.com/magento-2-theme-pearl

Anyone knows what could be happening?

3
  • 2
    Are the static files generated correctly ? Was there maybe a CDN before where the files were synced ?
    – Cladiuss
    Commented May 27 at 11:38
  • Yes the static, cache, etc gave me no problem or error. @Cladiuss
    – prgrm
    Commented May 27 at 12:13
  • 1
    If the backend is working correctly without any issues, the issue most probably lies with your third party theme, you should try switching the theme to luma first and see if the error remains to narrow down the issue. Commented Jun 6 at 4:59

3 Answers 3

0

It looks like your frontend static files are not being generated correctly. Check file permissions are not 'root' or something similar by running the following in the shell.

ls -la

I find the following works for 'resetting' the static files generation

rm -rf var/cache/* var/page_cache/* var/generation/* generated/code/*;
php bin/magento setup:di:compile;
php bin/magento setup:static-content:deploy -f en_AU en_US;
// above is for AU and US locations, include yours if different
php bin/magento c:f;
php bin/magento c:c;
0

Try to run the following commands :

php bin/magento cache:clean
php bin/magento cache:flush
php bin/magento indexer:reindex
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
sudo chmod -R 777 var/ generated/ pub/

Confirm all the command running without any error. Then try to set the website into production mode like this :

php bin/magento deploy:mode:set production
-1

Migrating a Magento 2 shop to a new server can sometimes result in issues, including JavaScript problems. Here are some steps to troubleshoot and resolve these issues:

1. Clear Cache and Reindex:

  • Clear Cache:

    php bin/magento cache:clean
    php bin/magento cache:flush
    
  • Reindex:

    php bin/magento indexer:reindex
    

2. Deploy Static Content:

Ensure that the static content is properly deployed. Run the following command to deploy static files:

php bin/magento setup:static-content:deploy

For specific locales, add the locale code, e.g., en_US:

php bin/magento setup:static-content:deploy en_US

3. Check File and Folder Permissions:

Ensure that the file and folder permissions are correctly set:

find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
chown -R :www-data .
chmod u+x bin/magento

Replace www-data with the appropriate web server user.

4. Check the Base URL Configuration:

Ensure that the base URLs are correctly set in the database:

SELECT * FROM core_config_data WHERE path LIKE '%base_url%';

Update if necessary:

UPDATE core_config_data SET value = 'http://your-new-domain.com/' WHERE path = 'web/unsecure/base_url';
UPDATE core_config_data SET value = 'https://your-new-domain.com/' WHERE path = 'web/secure/base_url';

5. Check .htaccess or Nginx Configuration:

Ensure that your .htaccess or Nginx configuration files are correctly set up for the new server.

6. Verify JavaScript Loading:

Open your browser's developer tools (F12), and check the console for any JavaScript errors. Also, check the Network tab to ensure that all JavaScript files are loading correctly.

7. Enable Developer Mode:

Switch to developer mode to get more detailed error messages:

php bin/magento deploy:mode:set developer

8. Check Magento Logs:

Look into the var/log and var/report directories for any error logs that might give you more information.

9. Check Browser Caching:

Sometimes, browser caching can cause issues. Clear your browser cache or try accessing the site in an incognito window.

10. Inspect Third-Party Extensions:

If you have third-party extensions, they might be causing conflicts. Disable them one by one to identify any problematic extensions.

php bin/magento module:disable Vendor_ModuleName
php bin/magento setup:upgrade

11. Review Server Configuration:

Ensure that your server configuration (PHP version, MySQL version, etc.) is compatible with Magento 2 requirements.

12. Run Magento Setup Upgrade:

Running the setup upgrade command can resolve many issues:

php bin/magento setup:upgrade

13. Check for Missing Files:

Ensure that all files were properly transferred during the migration. Missing or corrupted files can lead to JavaScript issues.

By following these steps, you should be able to identify and fix the JavaScript issues after migrating your Magento 2 shop to a new server. If the problem persists, please provide specific error messages or logs, and I'll help you further troubleshoot the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.