Enable code completion for node_modules in WebStorm

。_饼干妹妹 提交于 2019-12-11 06:14:59

问题


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');
    });
});

I get squiggly lines under the have call, and WebStorm tells me Unresolved variable have.

If I F12 on the to, WebStorm takes me to another node module, shelljs, but I haven't imported that one.

Is this because WebStorm can't resolve everything in javascript?

I've enabled Coding Assistance for NodeJS as per the docs, but that made no difference.


回答1:


Problem is caused by weird dynamic way these chai methods are defined. As a workaround I can suggest using chai.d.ts:

  • Open "Settings | Languages & Frameworks | JavaScript | Libraries"

  • Click "Download..." button and select "TypeScript community stubs"

  • Find "chai" and click "Download and Install".

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



来源:https://stackoverflow.com/questions/39346505/enable-code-completion-for-node-modules-in-webstorm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!