Using arcgis-webpack-plugin when site runs under a subdirectory

07-27-2020 08:32 AM
New Contributor

I am trying to use the the webpack plugin (GitHub - Esri/arcgis-webpack-plugin: Webpack plugin for the ArcGIS API for JavaScript ) with our Angular9 application.  I have based it on the example project provided here -> GitHub - Esri/angular-cli-esri-map at arcgis-webpack-angular 

One key difference is that our site runs under a sub-directory rather than a top-level domain.  For instance, our application runs under rather than .  This seems to cause a problem with where the js files are loaded.  For instance, when I hit a page that tries to render the map, I get a bunch of 404 errors when loading the esri javascript files because it is trying to load them from rather than

If I look at, I see the relevant javascript file.

Is there somewhere to configure the path to our application so that the esri webpack plugin will load files from the subdirectory rather than the top level domain?  This app runs on a multi-tenant server with multiple applications, so I can't host the js files from the top level...

(function(){ (this||window)["webpackJsonp"].registerAbsMids({ 	"esri/core/cookie":"./node_modules/arcgis-js-api/core/cookie.js", 	"esri/identity/IdentityForm":"./node_modules/arcgis-js-api/identity/IdentityForm.js", 	"esri/identity/IdentityManager":"./node_modules/arcgis-js-api/identity/IdentityManager.js", 	"esri/identity/IdentityManagerBase":"./node_modules/arcgis-js-api/identity/IdentityManagerBase.js", 	"esri/identity/IdentityModal":"./node_modules/arcgis-js-api/identity/IdentityModal.js", 	"esri/identity/OAuthCredential":"./node_modules/arcgis-js-api/identity/OAuthCredential.js", 	"esri/identity/OAuthInfo":"./node_modules/arcgis-js-api/identity/OAuthInfo.js", 	"esri/identity/ServerInfo":"./node_modules/arcgis-js-api/identity/ServerInfo.js" }) })(),(window["webpackJsonp"] = window["webpackJsonp"] || []).push([[49],{  /***/ "./node_modules/arcgis-js-api/core/cookie.js": /*!***************************************************!*\   !*** ./node_modules/arcgis-js-api/core/cookie.js ***!   \***************************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) {  var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;// COPYRIGHT © 2020 Esri // // All rights reserved under the copyright laws of the United States // and applicable international laws, treaties, and conventions. // // This material is licensed for use under the Esri Master License // Agreement (MLA), and is bound by the terms of that agreement. // You may redistribute and use this code without modification, // provided you adhere to the terms of the MLA and include this // copyright notice. // // See use restrictions at // // For additional information, contact: // Environmental Systems Research Institute, Inc. // Attn: Contracts and Legal Services Department // 380 New York Street // Redlands, California, USA 92373 // USA // // email: // // See for details.  !(__WEBPACK_AMD_DEFINE_ARRAY__ = [,exports], __WEBPACK_AMD_DEFINE_RESULT__ = (function(e,i){Object.defineProperty(i,"__esModule",{value:!0}),i.writeCookie=function(e,i,o){void 0===o&&(o={});var r=o.expires;if("number"==typeof r){var t=new Date;t.setTime(t.getTime()+24*r*60*60*1e3),r=o.expires=t}"string"!=typeof r&&(o.expires=r.toUTCString());var n=e+"="+encodeURIComponent(i);for(var f in o){n+="; "+f;var p=o;!0!==p&&(n+="="+p)}document.cookie=n}}).apply(null, __WEBPACK_AMD_DEFINE_ARRAY__), 				__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));  /***/ }),

Here is my package.json:

  "scripts": {
    "start""ng serve",
    "build""ng build --watch --extract-css",
    "build-prod""ng build --prod --output-hashing=none",
    "test""ng test",
    "test-headless""ng test --watch=false --browsers=ChromeHeadless",
    "test-coverage""ng test --watch=false --browsers=ChromeHeadless --codeCoverage=true ",
    "test-headless-firefox""ng test --watch=false --browsers=FirefoxHeadless",
    "lint""ng lint",
    "e2e""ng e2e",
    "bundle-report""ng build --prod --stats-json && webpack-bundle-analyzer wwwroot/application/dist/stats.json"
  "dependencies": {
  "devDependencies": {

Here is my angular.json:

  "projects": {
    "ExampleProject": {
      "schematics": {
        "@schematics/angular:component": {
      "architect": {
        "build": {
          "options": {
            "customWebpackConfig": {

            "assets": [
            "styles": [
            "scripts": [],
            "stylePreprocessorOptions": {
              "includePaths": ["node_modules/@fcsa/nitro-style/dist"]
          "configurations": {
            "production": {
              "fileReplacements": [
              "budgets": [
        "serve": {
          "options": {
          "configurations": {
            "production": {
        "extract-i18n": {
          "options": {
        "test": {
          "options": {
            "assets": ["clientApp/favicon.ico""clientApp/assets"],
            "styles": ["clientApp/styles.scss"],
            "scripts": [],
            "stylePreprocessorOptions": {
              "includePaths": ["node_modules/@fcsa/nitro-style/dist"]
        "lint": {
          "options": {
            "tsConfig": [
            "exclude": ["**/node_modules/**"]

Here is my webpack.config.js

const ArcGISPlugin = require('@arcgis/webpack-plugin');

module.exports = {
  plugins: [new ArcGISPlugin({
    features: {
      '3d': false
  node: {
    process: false,
    global: false,
    fs: "empty"
0 Kudos
3 Replies
Frequent Contributor

Just testing this out with a regular webpack build and I think this is working.

Update your webpack config like this.

// webpack.config.js
output: {
path: path.resolve(__dirname, 'dist/map'),
filename: "[name].[chunkhash].js",
publicPath: "/map/"

// plugins
new ArcGISPlugin({
features: {
"3d": false
environment: {
root: "/map",

// You could modify the HtmlWebPackPlugin
// to output the index.html to the
// root of the output
new HtmlWebPackPlugin({
title: "ArcGIS Template Application",
template: "./src/index.html",
filename: "../index.html", // up one from /map/
favicon: "./src/assets/favicon.ico",
chunksSortMode: "none",
inlineSource: ".(css)$"

In testing, it looks like all paths in the build will refer to the /map/ directory and all files will be copied there. The index.html is also copied there, but, I noted in the snippet that you can define the correct place for it.

0 Kudos
New Contributor

Thanks so much Rene!. That seems to have fixed that issue, but I have uncovered another problem.  Our map now loads, but I get a bunch of errors along the following lines:

dojo.js:6 DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'https://.../arcgis-js-api/layers/support/TileInfo.js' failed to load.

dojo.js:6 DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'https://.../arcgis-js-api/views/2d/ViewState.js' failed to load.
dojo.js:6 DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'https:/.../arcgis-js-api/layers/support/TileInfo.js' failed to load.

Initial research points to this thread (Error loading Pipeline.js - Angular & ArcGIS API For JavaScript ), where you actually responded and mentioned that "somewhere you need to set up the worker loader url configuration."  I did see this mentioned in the github documentation for the webpack plugin, which refers to is as an "external loader." (GitHub - Esri/arcgis-webpack-plugin: Webpack plugin for the ArcGIS API for JavaScript ).  I am just so confused as to where I am supposed to reference the "external loader" code, that is shown below:

Does this "external loader" need to be tied into our webpack.config.js somehow?  Does this code just need to be included in my angular project somewhere, and referenced at runtime (looks to be what this guy is doing esri-webpack/esri-map.component.ts at master · ronavraham/esri-webpack · GitHub )

Is there a working example of using this "external loader" with an angular project?  It doesn't seem to be used in the sample angular webpack project.

import esriConfig from "esri/config";const DEFAULT_WORKER_URL = "";const DEFAULT_LOADER_URL = `${DEFAULT_WORKER_URL}dojo/dojo-lite.js`;esriConfig.workers.loaderUrl = DEFAULT_LOADER_URL;esriConfig.workers.loaderConfig = {  baseUrl: `${DEFAULT_WORKER_URL}dojo`,  packages: [    { name: "esri", location: `${DEFAULT_WORKER_URL}esri` },    { name: "dojo", location: `${DEFAULT_WORKER_URL}dojo` },    { name: "dojox", location: `${DEFAULT_WORKER_URL}dojox` },    { name: "dstore", location: `${DEFAULT_WORKER_URL}dstore` },    { name: "moment", location: `${DEFAULT_WORKER_URL}moment` },    { name: "@dojo", location: `${DEFAULT_WORKER_URL}@dojo` },    {      name: "cldrjs",      location: `${DEFAULT_WORKER_URL}cldrjs`,      main: "dist/cldr"    },    {      name: "globalize",      location: `${DEFAULT_WORKER_URL}globalize`,      main: "dist/globalize"    },    {      name: "maquette",      location: `${DEFAULT_WORKER_URL}maquette`,      main: "dist/maquette.umd"    },    {      name: "maquette-css-transitions",      location: `${DEFAULT_WORKER_URL}maquette-css-transitions`,      main: "dist/maquette-css-transitions.umd"    },    {      name: "maquette-jsx",      location: `${DEFAULT_WORKER_URL}maquette-jsx`,      main: "dist/maquette-jsx.umd"    },    { name: "tslib", location: `${DEFAULT_WORKER_URL}tslib`, main: "tslib" }  ]};
New Contributor III

Any progress with this?  I think I am in the exact same boat.  I have setup the sample on github and have the map working but as soon as I try and do anything else (i.e. add a feature layer) I get the Error loading Pipeline.js.  I've also seen the github site and other forum posts about default workers but can't figure out how to get it to work.

0 Kudos