Error: The variable __WEBPACK_EXTERNAL_MODULE_XX__ has not been defined

A unique npm package called our-map has been developed utilizing TypeScript, webpack, and the ArcGIS JS API to encapsulate an esri map within a React component. The functionality of the module has been verified through testing on a dedicated page within the module itself, demonstrating the ability to showcase the React Map Component and retrieve web maps successfully. The our-map npm package has been saved to a file share for easy installation in other applications via npm.

The package was installed using npm install into our-app, which is another TypeScript application. After bundling the application with webpack, however, an error is encountered during runtime:

Uncaught ReferenceError: __WEBPACK_EXTERNAL_MODULE_61__ is not defined

Upon investigation using Chrome debugger, the problematic module is identified as follows:

module.exports = __WEBPACK_EXTERNAL_MODULE_61__;

//////////////////
// WEBPACK FOOTER
// external "esri/arcgis/utils"
// module id = 61
// module chunks = 0

When attempting to remove the esri/arcgis/utils module from the our-map module and republishing, a similar error occurs, now referring to the subsequent esri module.

The code structure for our-app is outlined below:

index.html

<!DOCTYPE html>
<html>
  <head>
    <title>Our Application</title>
  </head>

  <body>
    <div id="header"></div>
    <div id="content"></div>
    <div id="footer"></div>
    <script src="https://js.arcgis.com/3.16/"></script>
    <script>
            require(["dist/main.bundle.js"], function (main) {});
        </script>
  </body>
</html>

app.tsx Simplified for clarity

import * as React from "react";
import {MapContainer} from "our-map";

export const App = (props: IApp) => {
    return <div style={{height: "100%"}}>
        <div style={mapStyle}>
            <MapContainer />
        </div>
    </div>;
};

webpack.config.js

var webpack = require("webpack");

module.exports = {
    entry: {
        main: ['./src/app/main.ts', 'esri', 'esri/map', 'esri/urlUtils', 'esri/geometry/Point', 'esri/arcgis/utils']
    },
    output: {
        filename: 'dist/[name].bundle.js'
    },
    resolve: {
        extensions: ['', '.webpack.js', '.web.js', '.ts', '.tsx', '.js']
    },
    module: {
        loaders: [
            //typescript
            {
                test: /\.tsx?$/,
                loader: 'ts-loader'
            },
            // css
            {
                test: /\.css$/,
                loader: "style-loader!css-loader"
            },
            // images
            {
                test: /\.png$/,
                loader: "url-loader",
                query: { mimetype: "image/png" }
            },
            // fonts
            {
                test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
                loader: "url-loader?limit=10000&name=dist/fa/[hash].[ext]&mimetype=application/font-woff"
            },
            {
                test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
                loader: "file-loader?name=dist/fa/[hash].[ext]"
            }
        ]
    },
    externals: [
        function(context, request, callback) {
            if (/^dojo/.test(request) ||
                /^dijit/.test(request) ||
                /^esri/.test(request)
            ) {
                return callback(null, "amd " + request);
            }
            callback();
        }
    ],
    devtool: 'source-map'
};

If you have any insights on identifying the root cause of this issue and suggestions for resolving it, please share them!

Answer №1

To resolve the issue, I added libraryTarget: 'amd' to the webpack.config.js file as shown below:

output: {
    filename: 'dist/[name].bundle.js',
    libraryTarget: 'amd'
},

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Set the GridToolbarQuickFilter text box to have an outlined style in Material UI v5

How can I customize the appearance of the GridToolbarQuickFilter textbox, such as outlining it? Ideally, I would like to accomplish this through theme.tsx, but I am open to any suggestions. https://i.stack.imgur.com/H1Ojj.png I have experimented with var ...

After selecting an item, the Next UI navbar menu seems to have trouble closing

Having trouble with the navbar menu component not closing when an option is selected from the menu. The menu does open and close successfully within the menu icon. I attempted to use onPress() but it doesn't seem to be working as expected. "use c ...

Is there a hashing algorithm that produces identical results in both Dart and TypeScript?

I am looking to create a unique identifier for my chat application. (Chat between my Flutter app and Angular web) Below is the code snippet written in Dart... String peerId = widget.peerid; //string ID value String currentUserId = widget.currentId ...

Having trouble with node package installation?

I recently started working with nodejs and encountered an error when trying to run npm install in my project. npm ERR! Windows_NT 6.1.7601 npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\ ...

Discovering the power of chaining operators in RxJS 6 by encapsulating .map within

I am in the process of updating my Observable code from RXJS 5 to version 6. import { Injectable } from '@angular/core'; import { Observable } from 'rxjs' import { AppConfig } from '../config/app-config'; import { Xapi } from ...

Eliminate the alert message that appears when dynamically rendering a React styled component

When checking the browser console, I noticed a warning that reads as follows: react_devtools_backend.js:3973 The component styled.div with the id of "sc-dmRaPn" has been created dynamically. You may see this warning because you've called sty ...

The vertical scrolling functionality of the MUI DataGrid in Safari may occasionally fail to work

Utilizing the <Box> component from MUI core and the <DataGrid> component from MUIX, along with some other components, I have created a data grid that has the following appearance: https://i.sstatic.net/Gc8sP.png When the number of rows exceed ...

Automatically append version number to requests to avoid browser caching with Gulp

When deploying my project, I utilize gulp to build the source files directly on the server. In order to avoid caching issues, a common practice is to add a unique number to the request URL as explained in this article: Preventing browser caching on web app ...

Having trouble configuring Jest for TypeScript integration

I am currently implementing unit testing for a typescript project following the guidelines in this example: https://dev.to/muhajirdev/unit-testing-with-typescript-and-jest-2gln In my project, I have a file named main.ts that exports an isInternalLink func ...

Getting hold of parameters passed through npm run-script

The command I execute is: npm run a_script --oki="odo" Is there a way to access the value of oki in my script? My intention is to use it like this: if(process.argv.oki === 'odo'). I attempted to do this: console.log(process.argv); However, i ...

Issue encountered while utilizing npm on Visual Studio 2015

I'm attempting to run my Angular2 project with Visual Studio 2015. It works perfectly when I start it using npm in the windows console with the command 'npm start'. However, when trying to do the same thing using npm Task Runner for VS, I e ...

There was an error during compilation in the file ./src/App.js at Line 30:3 stating that the function 'onInputChange' is not defined as per the no

An error has occurred ./src/App.js Line 30:3: 'onInputChange' is not defined no-undef Take note of the keywords provided to understand each error. This issue arose during the building process and must be addressed. The content of App.js file ...

Is there a way to ensure in TypeScript that a generic type includes a property that implements a particular method?

To better explain my query, let me provide an illustration. Suppose I aim to create a method that accepts three parameters, as shown below: customFilter<T>(values: T[], filterString: string, propName: string) any[] { return values.filter((value) ...

WebpackError: The property 'node' cannot be accessed because it is undefined

Currently, I am exploring the capabilities of Gatsby.js and experimenting with creating a production build using the command gatsby build. However, during the process of building the HTML pages, an error message pops up in the terminal which says: error ...

Encountering a compilation error when implementing ActionReducerMap in combination with StoreModule.forFeature

In my Angular project, the structure is organized as follows: /(root or repo folder) |_ projects |_ mylib (main library to be exported from the repo) |_ sample-app (created for testing 'mylib' project in other projects) To manage appli ...

creating a JSON array within a function

I am currently developing an Angular application and working on a component with the following method: createPath(node, currentPath = []){ if(node.parent !==null) { return createPath(node.parent, [node.data.name, ...currentPath]) } else { retu ...

Resolving Typescript custom path problem: module missing

While working on my TypeScript project with Express.js, I decided to customize the paths in my express tsconfig.json file. I followed this setup: https://i.stack.imgur.com/zhRpk.png Next, I proceeded to import my files using absolute custom paths without ...

Tips for avoiding the transmission of className and style attributes to React components

Hey there! I'm working on a custom button component that needs to accept all ButtonHTMLAttributes except for className and style to avoid any conflicts with styling. I'm using TypeScript with React, but I've run into some issues trying to ac ...

An HTTP Request spam was initiated from the webpage

Lately, my web application has been bombarded with spam HTTP requests coming from the web URL. When I checked in the Chrome network tab, I noticed that multiple ".wasm" files were being requested. Can anyone provide suggestions on how to prevent this? Coul ...

We are unable to connect to github.com as the hostname cannot be resolved: Name or service is

We started encountering the issue of receiving the error message, "Could not resolve hostname github.com: Name or service not known" after upgrading our npm version from 6.14.14 to 8.1.2 when attempting to execute "npm publish" for our private package in o ...