Imported bindings should be defined and exported from the requested module

  • UNDEFINED_IMPORT
  • Error
  • Medium
  • es6

This rule applies when an imported binding is not exported from the requested module.

Importing the bindings not exported from the requested modules results in a SyntaxError exception when a module bundler is not used.
When bundling with Webpack, a warning message is given and the name will be bound to undefined. Note that if the imported binding is not referenced at all, Webpack gives no warning.

Note: This rule doesn't apply when the importing module uses TypeScript or Flow types, or the imported module is CommonJS.

Noncompliant Code Example

View with compliant examples side by side
// ./def.js
export const foo = 'foo is defined';
class bar {
    // do something
}

// ./use.js
import {
    notFoo, // UNDEFINED_IMPORT alarm
    bar // UNDEFINED_IMPORT alarm
} from './def.js';
import * as def from './def.js';
console.log(def.bar); // UNDEFINED_IMPORT alarm

Compliant Code Example

View with noncompliant examples side by side
// ./def.js
export const foo = 'foo is defined';
export class bar {
    // do something
}

// ./use.js
import {
    foo,
    bar
} from './def.js';
import * as def from './def.js';
console.log(def.bar);

Version

This rule was introduced in DeepScan 1.19.0.

See

Was this documentation helpful?