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!