Integrating Node with @arcgis/core
can be done by building the app with native ESM in a supported Node version or by transpiling to CommonJS.
// rollup.config.js
import commonjs from "@rollup/plugin-commonjs";
import resolve from "@rollup/plugin-node-resolve";
import typescript from "@rollup/plugin-typescript";
export default {
input: ["src/request.ts", "src/projection.ts", "src/webmap.ts"],
output: {
chunkFileNames: "chunks/[name].js",
dir: "dist",
format: "cjs"
},
external: ["whatwg-fetch"],
plugins: [typescript(), resolve(), commonjs()],
preserveEntrySignatures: false
};
Because Node does not have a native fetch
, you will need to load a polyfill.
require("cross-fetch/polyfill");
You will also want to disable the IdentityManager
so it doesn't attempt to load DOM related JavaScript.
import esriConfig from "@arcgis/core/config";
esriConfig.request.useIdentity = false;