I tried to add a main.js to my Magento theme using the answer on How To add JS file in frontend for all pages, however, it caused issues so I removed this, however, I still get console error for this.

Uncaught SyntaxError: Unexpected token } in JSON at position 199
at JSON.parse (<anonymous>)
at getData (http://domain.dev/products/pub/static/version1497885161/frontend/aa/aa-theme/en_US/mage/apply/main.js:51:24)
at Array.map (native)
at HTMLDocument.apply (http://domain.dev/products/pub/static/version1497885161/frontend/aa/aa-theme/en_US/mage/apply/main.js:67:18)
at fire (http://domain.dev/products/pub/static/version1497885161/frontend/aa/aa-theme/en_US/jquery.js:3232:32)
at Object.add [as done] (http://domain.dev/products/pub/static/version1497885161/frontend/aa/aa-theme/en_US/jquery.js:3291:8)
at jQuery.fn.init.jQuery.fn.ready (http://domain.dev/products/pub/static/version1497885161/frontend/aa/aa-theme/en_US/jquery.js:3542:26)
at jQuery.fn.init (http://domain.dev/products/pub/static/version1497885161/frontend/aa/aa-theme/en_US/jquery.js:2967:11)
at jQuery.fn.init (http://domain.dev/products/pub/static/version1497885161/frontend/aa/aa-theme/en_US/jquery/jquery-migrate.js:225:17)
at jQuery (http://domain.dev/products/pub/static/version1497885161/frontend/aa/aa-theme/en_US/jquery.js:75:11)

I've tried to resolve this by removing the contents of pub/static and ran the PHP bin/magento setup:static-content: deploy but the console error still appears and is causing all javascript elements on my Magento site to not work.

  • Just had this myself. My cause was because I left a rogue , at the end of some JSON configuration in one of my templates for a knockout component.
    – Tom Burman
    Commented Aug 10, 2017 at 16:55

2 Answers 2


Try clearing browser cache if you haven't already, I've had this a few times when I forgot to clear it.

Also make sure you have un-done the steps you took to add it, so remove the related JS from the require JS config to.

  • Yeah i've cleared both Magento and browser caches. I've completely removed it from the theme but I'm not 100% sure whether this is from the main.js I tried to add or others as I searched the complete site and there are still references to main.js in other 'core?' files.
    – lky
    Commented Jun 19, 2017 at 16:39

Remove pub/static folder content and /var/view_processed or php bin/magento setup:upgrade (this remove all static content) ,then deploy

  • Unfortunately didn't resolve my error :( Do i need to re-run Magento compile command when it asks?
    – lky
    Commented Jun 19, 2017 at 16:02
  • Which thing you have done can you write step Commented Jun 19, 2017 at 16:03
  • Ive tried removing pub/static contents and /var/view_processed/ then ran php bin/magento setup:static-content:deploy. Also tried to run php bin/magento setup:upgrade, but didn't run the compile command when it asked, just ran php bin/magento setup:static-content:deploy. I then cleared cache by php bin/magento cache:flush but error still showing.
    – lky
    Commented Jun 19, 2017 at 16:09
  • Just tired this again and ran the compile command when it asks, but still no luck :(
    – lky
    Commented Jun 19, 2017 at 16:13
  • 1) remove var/view_processed Commented Jun 19, 2017 at 16:15

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.