When I use require
in my JavaScript, I get a warning from eslint, "require is not defined eslint(no-undef)".
Except for this one file, all the files in my project uses the browser env
, which is set in my .eslintrc
.
How can I make an exception and specify a node env for just this one file?
var fs = require('fs');
var path = require('path');
// my code
Similar to how you can override eslint rules with a code comment at the top of the file, you can also override the environment:
/* eslint-env node */
var fs = require('fs');
var path = require('path');
// my code
Setting the node environment will make it so that node features like require
and __dirname
are not treated as undefined.
See Specifying Environments in the eslint documentation.
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