On test.php over root, login authentication is working fine. While i am trying to implement 'Kakao' login/sign-up process in magento2, I have included 'kakao.js' in the respective login page, its loaded but its giving js error in console "Mismatched anonymous define() module: function ()".
here is the sample code through which I am using to include kakao.js over customer_account_login page -
path - app/code/MyCompany/CustomerAttribute/view/frontend/layout/customer_account_login.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<script src="MyCompany_CustomerAttribute::js/kakao.js" order = '5000'/>
</head>
I also create a requirejs-config.js file -
path - app/code/MyCompany/CustomerAttribute/view/frontend
var config = {
map: {
'*': {
kakao: 'MyCompany_CustomerAttribute/js/kakao'
}
}
};
kakao.js file included on customer login page by override customer_account_login.xml but its giving js error on console -
Uncaught Error: Mismatched anonymous define() module: function......require.js 166
Don't know what i am doing wrong.
I also tried by remove override customer_account_login.xml but than its not loading kakao.js
here is thel url of kakao.js - developers.kakao.com/sdk/js/kakao.min.js
Please help me sort-out this.
1 Answer 1
This is because you're not loading kakao.js via Require JS, with Magento 2 you should be using Require JS to load any JS. THe old XML method is no longer best practice.
You can see more info on the dev docs: - http://devdocs.magento.com/guides/v2.1/javascript-dev-guide/javascript/js_init.html - http://devdocs.magento.com/guides/v2.1/javascript-dev-guide/javascript/requirejs_concept.html
A quick example JS script
define(['jquery', 'kakao'], function(,ドル kakao) {
'use strict';
// Initialise Kakao here
});
-
Hi Ben, thx for reply. I already have requirejs-config.js at location - app/code/MyCompany/CustomerAttribute/view/frontend you can see in my post. And I run the setup:static-content:deploy after add this but result is same. or you are saying me to remove override customer_account_login.xml and run only with requirejs-config.js .? I did it but through this kakao.js not including in page .Atul– Atul2017年03月10日 12:27:00 +00:00Commented Mar 10, 2017 at 12:27
-
I would remove the XML and add it as a dependency via Require, I have updated my answer with an exampleBen Crook– Ben Crook2017年03月10日 12:44:38 +00:00Commented Mar 10, 2017 at 12:44
-
Thanks Ben, But there are some questions - in which file i need to define it like your way ? in requirejs-config.js ? or in some other file ? and where you write " Initialise Kakao here" what I need to write here 'code of kakao.js' or in short way how to initialize kakao here ?Atul– Atul2017年03月15日 04:06:02 +00:00Commented Mar 15, 2017 at 4:06
-
Hi @Atul - The JS in my answer will need to be in a new file, the location of the file depends on the area it affects. If it's for the login area I believe the best place would be
app/design/frontend/PartyShowroom/default/Magento_Customer/web//js/your-script.js. You just need to initialise Kakao, having a quick scan of the docs that isCocoa.initbut I may be wrong.Ben Crook– Ben Crook2017年03月15日 09:36:45 +00:00Commented Mar 15, 2017 at 9:36