Magento page console error Uncaught SyntaxError: Unexpected token } in JSON at position 530 while you have made mistake to your code.
Code with Error in a template file:
<script type="text/x-magento-init"> { "*": { "Magento_Ui/js/core/app" : { "components" : { "favoriteAddTo": { "component": "Rbj_Js/js/favorite", } } }, "Rbj_Js/js/login": { "users": "USER_IDS" }, } } </script>
Console Error:
Uncaught SyntaxError: Unexpected token } in JSON at position 530 at JSON.parse (<anonymous>) at getNodeData (scripts.js:87) at Array.map (<anonymous>) at scripts.js:117 at apply (main.js:77)
I have defined the above custom javascript block using the template file script tag. When checking the above code for the first time, looks correct but when we load the page with this javascript code, it will throw an error.
Here our issue is we have added an extra comma(,) at lines no. 7 and 13 that’s not needed at all.
Once you remove the extra comma from the Object-defined using script tag, your js issue will be resolved.
In the above code snippet, we have added two different places commas at lines no. 7 and 13 that will throw the error.
Correct Code:
Remove all the extra comma from the snippet that is not required in the Script tag.
<script type="text/x-magento-init"> { "*": { "Magento_Ui/js/core/app" : { "components" : { "favoriteAddTo": { "component": "Rbj_Js/js/favorite" } } }, "Rbj_Js/js/login": { "users": "USER_IDS" } } } </script>