简体   繁体   中英

JS importing non-existent variables

a.js:

export const something = "something";

b:.js:

import { somethingElse } from './a';

If we try to import a non-existent variable like the code above, is there a way to get warned about this? (through linters, webpack, IDE etc)

It seems you are looking for the eslint-plugin-import and its import/named rule:

import/named

Verifies that all named imports are part of the set of named exports in the referenced module.

Given:

 // ./foo.js export const foo = "I'm so foo" 

The following is considered valid:

 // ./bar.js import { foo } from './foo' 

...and the following are reported:

 // ./baz.js import { notFoo } from './foo' 

Details/docs: https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/named.md and the project's readme .

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM