I'm relying on a class that is available in browser, FileReader
I keep getting an error in webpack - 'FileReader' is not defined no-undef
What is the correct way of dealing with this? I'm currently using a method where I just ignore the message.
To clear a text input, assign blank string to 'value' attribute (not innerHTML attribute) document . getElementById("text"). value = ""; And don't call myfunction in JS tab If you use a <form> then an input with 'type' attribute "reset" will do the same thing.
Answer and Explanation: A function is not defined or is undefined if the value to be inputted is not in its domain.
The JavaScript exception "variable is not defined" occurs when there is a non-existent variable referenced somewhere.
The module type is used to make Node treat . js files as ES modules. Instead of require() , you need to use the import/export syntax. To solve the issue, remove the "type": "module" from your package.
The issue is that since webpack cannot find it as part of Node.js and since it is not available, it will cause an error. But there are a few ways of getting around this.
Instead of
var reader = new FileReader();
use
var reader = new window.FileReader();
var reader = new global.FileReader();
webpack, by default, will convert global to window. More info at: https://webpack.js.org/configuration/node/
// in webpack.config.js
module.exports = {
//...
externals: {
FileReader: 'FileReader'
}
};
more info: https://webpack.js.org/configuration/externals/
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