I'm using 4.20 api in my app with @arcgis/core. I have a custom layer manager widget I want to load and I've been using this method from the custom widget documentation, but it doesn't seem to work with ES modules. I have in my index:
<script>
var locationPath = location.pathname.replace(/\/[^\/]+$/, "");
window.dojoConfig = {
packages: [
{
name: "layer-manager",
location: locationPath + "./Widgets/LayerManager/app"
}
]
};
</script>
<script type="module" src="./app/main.js"></script>
...
<script>require(["layer-manager"]);</script>
then in my main.ts file I do:
import LayerManager = require("layer-manager/LayerManager");
I'm trying to use snowpack in dev mode to bundle and serve my code locally, but I'm getting the error:
Uncaught ReferenceError: require is not defined
from those lines in index and main.
I see the note in the docs that says:
Although Dojo has been removed from a majority of the API, it is still needed in this case to load the AMD modules.
I'm guessing none of my code is pulling in dojo, so it doesn't have access to require. I tried adding a script tag to my index.html:
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.14.1/dojo/dojo.js"></script>
but that gives me this error:
dojo.js.uncompressed.js:129 Uncaught Error: undefinedModule
I also see here https://developers.arcgis.com/javascript/latest/tooling-intro/#compare-amd-and-es-modules that esm local builds might not even be possible when using dojo1.
What is the recommended way for loading custom widgets and is it possible to load custom widgets using the ES modules and a bundler like snowpack?