37

if i write such code in webstorm

export class someOne {
  constructor(param) {
    this.test = param;
  }

  useTest(){
    return this.test;
  }
}


console.log(new someOne(123).useTest());

and mouseover on "this.test" i see the warning: "Element is not exported"

element is not exported wtf

what does it mean? if i change the .test to .test1 the warning disappears

3
  • 1
    If it works, and changing the variable name makes the warning go away -- I suspect it's a conflict with webstorm's understanding of variable names. I came across this with MongoDB function names triggering deprecation warnings for non-Mongo features Commented Apr 16, 2016 at 23:31
  • Weird error. I've gotten this too when exporting classes in IntelliJ IDEA 2016.1.1.
    – E. Sundin
    Commented Apr 19, 2016 at 3:19
  • 1
    Same here. PhpStorm 2016.1 Commented Apr 19, 2016 at 7:40

3 Answers 3

9

For me it worked to mark all "private" properties with a prefixed underscore. Obviously Webstorm/IntelliJ recognized the properties as something that should not be exported.

export class someOne {
  constructor(param) {
    this._test = param;
  }

  useTest(){
    return this._test;
  }
}


console.log(new someOne(123).useTest());
1
7

Webstorm just tries to prevent you adding unspecified attributes. You need to define getters/setters. This prevents adding and grabbing attributes as dirty hacks.

Update - added WeakMap to have variables really private.

let testWeakMap = new WeakMap();
export class someOne {
    constructor(param) {
        this.test = param;
    }

    useTest(){
        return this.test;
    }

    get test () {
        return testWeakMap.get(this);
    }

    set test (value) {
        testWeakMap.set(this, value);
    }
}
console.log(new someOne(123).useTest());
3
  • So what is proper way to make this warning go away?
    – redism
    Commented Apr 25, 2016 at 2:18
  • To simply suppress the warning, you can add //noinspection JSUnresolvedVariable before the property declaration.
    – Jbird
    Commented May 10, 2016 at 10:53
  • 14
    Or, in "Editor" > "Inspections" > "Javascript" > "General" > "Unresolved JavaScript variable" disable "Report undeclared properties as error" (PHPStorm 2016.1)
    – Jbird
    Commented May 10, 2016 at 11:00
0

This is a curious error-message which I suspect is probably caused by some bug(s) in WebStorm.

I have these 2 methods in a class in a .mjs -file:

 reports_elementIsNotExported_error ()
 { let abc = bad;
 }

 reports_unresolvedVariableOrType_error ()
 { let abc = bad77;
 }

When I run Code -> Inspect Code on this file the first method reports "Element is not exported".

The second one reports "Unresolved variable of type bad77"

I looked into my Node.js 'global' and neither 'bad' nor 'bad77' exists as a field of it. Why 'bad' should produce a different message than 'bad77' I have no idea.

Not the answer you're looking for? Browse other questions tagged or ask your own question.