本文介绍了Mocha描述了“require()缺失”。在WebStorm 11中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚安装了WebStorm 11并创建了一个新项目,但WebStorm表示 describe require() / code>方法:





我添加了绝对类型的mocha库,范围是测试目录(该文件所在的目录)。

解决方案

编辑:As在评论中指出,这个问题中解决的实际问题实际上是IntelliJ 15 / WebStorm 11中的一个错误(参见



列表中的库名为 mocha ,但会转换为 @ types / mocha (在2019年初之前,它将转换为 mocha-DefinitelyTyped )一旦导入。



一旦你有了mocha-DefinitelyTyped,取消选中它的Enabled复选框。完全检查它将使全局,甚至在测试之外,这将是不准确的。相反,我们将管理其范围仅在您的测试目录中启用。单击管理范围... 按钮,找到您的测试目录,单击Library列,然后选择'mocha-DefinitelyTyped'条目。请参阅下面的屏幕截图。




I've just installed WebStorm 11 and created a new project, however WebStorm is saying that a require() is needed for the describe method:

I've added the definitely-types mocha library and the scope is for the test directory (which this file is in).

解决方案

Edit: As noted in the comments, the actual issue addressed in this question is actually a bug in IntelliJ 15 / WebStorm 11 (see https://youtrack.jetbrains.com/issue/WEB-18768). I'm leaving the answer below because many people come here when searching for the solution provided.

The accepted answer is a sledgehammer approach to solving the problem. A better solution is to enable the mocha-DefinitelyTyped library for the test directory. Not only will this remove the erroneous inspection, it will provide better syntax highlighting.

From the description of the inspection:

Navigate to the preference section referenced above, ‘Preferences | Languages & Frameworks | JavaScript | Libraries’, and check if the mocha-DefinitelyTyped library is in the list.

If @types/mocha (used to be named mocha-DefinitelyTyped) is not in the list, click the Download… button, find ‘mocha’ in the ‘TypeScript community stubs’ section, select it, and click Download and Install:

The library is named just mocha in the list, but will convert into @types/mocha (prior to early 2019, it would convert to mocha-DefinitelyTyped) once imported.

Once you have mocha-DefinitelyTyped, uncheck its Enabled checkbox. Leaving it fully checked would enable it globally, even outside of tests, which would be inaccurate. Instead, we will manage its scope to be enabled only in your test directory. Click the Manage Scopes… button, find your test directory, click on the Library column, and select the ‘mocha-DefinitelyTyped’ entry. See the screenshot below.

这篇关于Mocha描述了“require()缺失”。在WebStorm 11中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 17:57