尝试在我的网站上添加 salesforce 身份验证和 api 调用时,出现以下三个错误。该代码在节点上本地运行良好
未捕获的 TypeError:jsforce.Connection 不是构造函数
未捕获(承诺中)TypeError:无法解析模块说明符'jsforce'
未捕获(承诺中)TypeError:无法解析模块说明符“xmlhttprequest”
// JSForce Authentication
var jsforce = import('jsforce');
var XMLHttpRequest = import("xmlhttprequest").XMLHttpRequest;
var conn = new jsforce.Connection({
loginUrl : 'https://test.salesforce.com'
});
conn.login('username_redacted_for_demo', 'KLJHiu76iUKAYIS87AI7as8878aslkxck', function(err, userInfo) {
if (err) {
console.log(JSON.stringify(err));
return console.error(err);
}
UserAction();
});
// Apex Rest API Call
function UserAction() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
}
};
xhttp.open("GET", "https://example.my.salesforce.com/services/apexrest/MDR_Account/");
xhttp.setRequestHeader("Authorization", "Bearer " + conn.accessToken);
xhttp.setRequestHeader("Content-type", "application/json");
xhttp.send();
}