I am migrating my web application from the 3.x to 4.x Esri javascript api. I need to load "esri/identity/IdentityManager" module to access by token to my arcgis server rest services. It works fine, if I don't load dojo. But It fails when I load it. It comes out this error:
dojo.js.uncompressed.js:1770 GET https://ajax.googleapis.com/ajax/libs/dojo/1.14.1/esri/identity/IdentityManager.js net::ERR_ABORTED 404
It looks like the application is looking for the esri module in the dojo toolkit...
Below I am adding a sample in which I've commented the references to the IdentityManager . This way it works. For this sample there is no need to use the token, but I include it to make it easier to understand the case.
Thanks in advance.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>DOJO and Esri javascript api 4.X</title>
<!-- Load dojo -->
<script src="https://ajax.googleapis.com/ajax/libs/dojo/1.14.1/dojo/dojo.js"></script>
<link
rel="stylesheet"
href="https://js.arcgis.com/4.28/esri/themes/light/main.css"
/>
<script src="https://js.arcgis.com/4.28/"></script>
<script>
require([
"esri/layers/FeatureLayer",
"esri/rest/support/Query",
//If commented references to IdentityManager, there is no problem
//"esri/identity/IdentityManager",
"dojo/dom", "dojo/on",
"dojo/domReady!"
], function (FeatureLayer, Query,
// esriId,
dom, on) {
var tokenStr="63dJGeEz6333YPz6T07uLpGEbbVsnRPLqVVnEVkqhUq.";
var token = {
"server": "https://sampleserver6.arcgisonline.com/arcgis/rest/services",
"token": tokenStr
};
// esriId.registerToken(token);
const countiesLayer = new FeatureLayer({
url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/3"
});
let queryCounties = countiesLayer.createQuery();
queryCounties.returnGeometry = false;
queryCounties.where = "state_name ='Washington'";
queryCounties.outFields = [ "OBJECTID", "state_name" ];
on(dom.byId("execute"), "click", execute);
function execute () {
countiesLayer.queryFeatures(queryCounties)
.then(function(response){
document.write(response.features[0].attributes.state_name);
});
}
});
</script>
</head>
<body>
<input id="execute" type="button" value="Query County">
</body>
</html>