WebStorm error: expression statement is not assignment or call

前端 未结 2 3030
小蘑菇
小蘑菇 2020-12-18 18:33

I\'m using WebStorm and I\'m getting an error that I can\'t understand. Node.js + MongoDB.

var mongoose = require(\'mongoose\');

mongoose.Promise = global.P         


        
相关标签:
2条回答
  • 2020-12-18 18:42

    You need to change JavaScript Language Version to ES6. Changing this setting should fix the issue:

    In some scenarios, you might need to restart your IDE for the changes to reflect properly.

    0 讨论(0)
  • 2020-12-18 19:00

    The problem is that WebStorm will show a warning if that statement isn't doing any of the following within a function:

    • Calling another function
    • Making any sort of assignment
    • Returning a value
    • (There may be more, but those are the ones I know of)

    In other words, WebStorm views that function as unnecessary and tries to help you catch unused code.

    For example this will show the warning:

    const arr = [1, 2];
    const willShowWarning = arr.map(num => {
        num + 1;
    });
    

    Adding a return will take the warning away:

    const arr = [1, 2];
    const willNotShowWarning = arr.map(num => {
        return num + 1;
    });
    

    The answer is not to change WebStorm settings.

    0 讨论(0)
提交回复
热议问题