In my library, I just have one component
MapTest.js
import React, { useRef, useEffect } from "react";
import MapView from "@arcgis/core/views/MapView";
import Map from "@arcgis/core/Map";
function MapTest() {
const _mapDiv = useRef(null);
useEffect(() => {
if (_mapDiv.current) {
const _view = new MapView({
container: _mapDiv.current,
map: new Map({
basemap: "topo-vector"
})
});
}
}, []);
return <div className="mapDiv" ref={_mapDiv}></div>;
}
export default MapTest;
rollup.config.js
import babel from "@rollup/plugin-babel";
import resolve from "@rollup/plugin-node-resolve";
import external from "rollup-plugin-peer-deps-external";
import postcss from "rollup-plugin-postcss";
import commonjs from "@rollup/plugin-commonjs";
import { terser } from "rollup-plugin-terser";
const devEnvironmentPlugins = [
external(),
postcss({ plugins: [], minimize: true }),
babel({ exclude: "node_modules/**", presets: ["@babel/preset-react"] }),
external(),
resolve(),
commonjs(),
terser(),
];
const config = [
{
input: "src/index.js",
output: [
{
dir: "dist/js",
format: "cjs",
sourcemap: true,
},
],
plugins: devEnvironmentPlugins,
external: ["react", "react-dom", "prop-types", "styled-components"],
},
{
input: "src/index.js",
output: [
{
dir: "dist/js",
format: "es",
sourcemap: true,
},
],
plugins: devEnvironmentPlugins,
external: ["react", "react-dom", "prop-types", "styled-components"],
},
];
export default config;
In my react application I'm consuming the library
import React from "react";
import { MapTest } from "@dltest/mapbuildtest";
import "./App.css";
function App() {
return <div id="root"><MapTest /></div>;
}
export default App;
The error that comes is
./node_modules/@dltest/mapbuildtest/dist/index-0ae0a047.js 64268:9
Module parse failed: Identifier 'e' has already been declared (64268:9)
File was processed with these loaders:
* ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| };
|
> for (var e = 48; e < 58; e++) {
| qJ[e] = String.fromCharCode(e);
| }