I’m using amcharts
(amcharts4) with React app(generated using cra).
I was able to successfully exclude few dependencies(cpexcel, canvg, pdfmake) using webpack Externals
in webpack.config
file (node_modules/react-scripts/config/webpack.config.js)
like this:
JavaScript
x
8
1
externals: [
2
function (context, request, callback) {
3
if (/cpexcel|canvg|pdfmake/.test(request)) {
4
return callback(null, "commonjs " + request);
5
}
6
callback();
7
}]
8
I also want to exclude the xlsx
dependency, but it throws error while building with this configuration:
JavaScript
1
8
1
externals: [
2
function (context, request, callback) {
3
if (/xlsx|canvg|pdfmake/.test(request)) {
4
return callback(null, "commonjs " + request);
5
}
6
callback();
7
}],
8
Error is:
JavaScript
1
7
1
$ react-scripts build
2
Creating an optimized production build
3
Failed to compile.
4
5
chunk runtime-main [entry]
6
Cannot convert undefined or null to object
7
I’m not using any csv feature of amcharts
.
Is there any other possible way to exclude xlsx
(without using standalone library and removing manually) in amcharts
?
Advertisement
Answer
The error was because of react-chartjs-2
. I was trying few chart libraries and I forgot to remove the library.
Successfully excluded the xlsx
library.
JavaScript
1
8
1
externals: [
2
function (context, request, callback) {
3
if (/xlsx|canvg|pdfmake/.test(request)) {
4
return callback(null, "commonjs " + request);
5
}
6
callback();
7
}],
8