I've been attempting to incorporate the jquery.md5.js plugin into my VueJs project, but I keep encountering an issue:
TypeError: (0 , _jquery.md5) is not a function
or
ERROR in ./src/utils-convenience/jquery.md5.js
Module build failed: SyntaxError: Unexpected token (23:2)
21 | /*global unescape, jQuery */
22 | export default {
23 | (function ($) {
| ^
24 | 'use strict';
25 |
26 | /*
I am utilizing Webpack in my project, although it's not my strong suit, leading me to believe there may be an issue with file imports. Any guidance would be appreciated.
Below is my code for both scenarios:
import axios from 'axios'
import { API_URL } from '../../config/constants'
import { md5 } from '../utils-convenience/jquery.md5'
export default {
// Retrieving data for main page
getEvents () {
return new Promise((resolve, reject) => {
var authId = 'api.kassy.ru'
var secretKey = 'a619d974658f3e749b2d88b215baea46'
var xml = '<?xml version="1.0" encoding="utf-8"?><request module="subdivision" format="json"><filter id="" db="" state="" /><auth id="' + authId + '" /></request>'
var sign = md5(xml + secretKey)
axios.post(API_URL, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest'
},
body: {
'xml': xml,
'sign': sign
}
})
.then((result) => {
console.log(result)
return resolve(result.data)
})
.catch(err => reject(err))
})
}
The first error occurs when I do not export the code from jquery.md5.js and simply import the file. The second error arises if I export the code as shown below:
export default {
(function ($) {
'use strict';
///MD5 code
}(typeof jQuery === 'function' ? jQuery : this));
}