Error when using dojo/text!

659
2
07-25-2023 02:05 PM
GBreen
by
Occasional Contributor

I'm getting an error when trying to upgrade from version 4.17 to 4.27:

Loading failed for the <script> with source “https://js.arcgis.com/4.27/dojo/text.js”.

 

I've narrowed down (I believe) the issue to using the "dojo/text!" in order to pull in text files. Did something change to cause this issue and is there a work around that I can use?

 

<script>
require(['dojo/text!cuwcd/widgets/Header/header.hbs'], function(hbs) {});
</script>
0 Kudos
2 Replies
ReneRubalcava
Honored Contributor

All non-Esri packages, including Dojo related packages, are no longer part of the released CDN builds. The old versions are still there though and can be configured for use. See the notes here.

https://developers.arcgis.com/javascript/latest/4.25/#removal-of-non-esri-packages-from-cdn

JoelBennett
MVP Regular Contributor

A lot has changed in those releases, including the removal of dojo as part of the API in 4.20.  I don't remember the technical specifics of what transpired, but I ended up making my own custom replacement for the text module.  It's called text.js, and I placed it within the root of my own package.  The implementation is very simple:

define([], function() {
	return {
		load: function(id, require, callback) {
			var url = require.toUrl(id);
			var prop = "url:" + url;
			var cacheVal = require.cache[prop];

			if (typeof cacheVal == "string")
				callback(cacheVal);
			else {
				fetch(require.toUrl(id), {credentials:"include"}).then(function(response) {
					response.text().then(function(text) {
						require.cache[prop] = text;

						callback(text);
					});
				});
			}
		}
	};
});

 

So then, if you put this text.js file directly in the directory represented by "cuwcd", your function call would change to:

require(["cuwcd/text!cuwcd/widgets/Header/header.hbs"], function(hbs) {
	//etc
});