I'm doing the following in a js file
var FS = require('fs');
var TestGoogle = eval(FS.readFileSync('../loader.js', 'utf8'));
I added to my webpack config:
node: {
fs: "empty"
}
The webpack compiles with Babel but I get an error in the js console
FS.readFileSync is not a function
Why is this? I would simply like to import a javascript file. Specifically in order to use material bar charts of google. https://developers.google.com/chart/interactive/docs/gallery/barchart#creating-material-bar-charts
In vanilla js, I need to
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['bar']});
And then, as the tutorial states, use google.charts.Bar instead of google.visualization.BarChart. Unfortunately, I can't get this simple vanilla JS to play nicely with Node.js, Babel, Webpack.
Webpack provides a Node. js API which can be used directly in Node. js runtime.
There is no need to install fs in node js to use it.
Working with system files technically works on all modern browsers.
Try add target: 'node'
to webpack.config.js. I had the same problem and it solved for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With