在WebStorm中为node_modules启用代码完成 [英] Enable code completion for node_modules in WebStorm
问题描述
我是WebStorm的新手,也是Node开发的新手.我正在开发一个现有项目,并且想为我的node_modules完成代码.更具体地说,我使用的是Chai,WebStorm似乎找不到我的expect.to
语句的.have
成员.
I'm new to WebStorm, and fairly new to Node development. I am working on an existing project, and want to have code completion for my node_modules. More specifically, I'm using Chai and WebStorm doesn't seem to find the .have
member of my expect.to
statement.
这是我的代码,简化了:
This is my code, simplified:
var expect = require('chai').expect;
import {Customer} from '../../app/model/Customer.js';
describe('...', function() {
it('...', function() {
var customer = new Customer();
expect(customer).to.have.property('name');
});
});
在have
调用下出现弯曲的行,WebStorm告诉我Unresolved variable have
.
I get squiggly lines under the have
call, and WebStorm tells me Unresolved variable have
.
如果我在to
上按F12键,WebStorm会将我带到另一个节点模块shelljs,但是我尚未导入该模块.
If I F12 on the to
, WebStorm takes me to another node module, shelljs, but I haven't imported that one.
这是因为WebStorm无法解析javascript中的所有内容吗?
Is this because WebStorm can't resolve everything in javascript?
我已将NodeJS的编码协助启用为,但这没什么区别.
I've enabled Coding Assistance for NodeJS as per the docs, but that made no difference.
推荐答案
问题是由定义这些chai方法的奇怪动态方式引起的.作为一种解决方法,我建议使用chai.d.ts:
Problem is caused by weird dynamic way these chai methods are defined. As a workaround I can suggest using chai.d.ts:
-
打开"
Settings | Languages & Frameworks | JavaScript | Libraries
"
单击"Download...
"按钮,然后选择"TypeScript社区存根"
Click "Download...
" button and select "TypeScript community stubs"
找到"chai",然后单击"Download and Install
".
Find "chai" and click "Download and Install
".
请参见 http://blog.jetbrains.com/webstorm/2014/07/how-webstorm-works-completion-for-javascript-libraries/,使用TypeScript社区存根(TypeScript定义文件)"以获取更多信息
See http://blog.jetbrains.com/webstorm/2014/07/how-webstorm-works-completion-for-javascript-libraries/, 'Using TypeScript community stubs (TypeScript definition files)' for more information
这篇关于在WebStorm中为node_modules启用代码完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!