while checking import/ export feature, it was surprising to see that if a named property is used in import and it is not defined in the exported file than it does not throw any error?
below is the example
export const ALPHA = 'alpha';
export const BETA = 'beta';
import {ALPHA, BETA, GAMMA} from './export_'
console.log("alpha is ", ALPHA);
console.log("beta is", BETA);
console.log("gamma is", GAMMA);
Here GAMMA
is not defined in _export.js but do not throw any error regarding this in _import.js ?
I was facing this issue as I have accidentally imported a wrong file ( same file name in 2 directories) in import
statement but it does not throw any error that the given exported named property is not found in the file.
Is this behavior is correct?
or
Is there any linting rule in linter ( eg. eslint) available which identifies such mistake and throws error or warning to the developer?
As far as i know, esLint doesnt provide this check out of the box.
You may want to use eslint-plugin-import .
I use it and it throws an error of import/named
when a module wasn't found.
For example:
MyModule not found in '../../modules'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.