IntelliJ / WebStorm node.js代码完成与(自定义)所需模块不工作/未解决的功能?

时间:2016-10-20 12:12:50

标签: node.js intellij-idea webstorm

例如,如果我有这段代码(posts.js

var mongoose = require('mongoose');

var postsSchema = mongoose.Schema({
    _id: Number,
    title: String,
    description: String,
    comments: [{ type: String, minlength: 1, required: true }]
});    
var Post = mongoose.model('Posts', postsSchema);    
module.exports = Post;

并将在某处使用此模型,例如:

var Post = require('../models/posts');
Post.{strg+space}

它可以工作,但我不能使用代码完成,如果我调用一个函数,我会在IntelliJ编辑器中看到“未解析函数”的错误。

如果我将导出更改为:

module.exports = {Post:Post};    

exports.Post = Post;

并导入模型:

var Post = require('../models/posts').Post;
一切似乎都很好。

这是一个错误还是我做错了什么?

code completition problem

code completition after export with identifier

2 个答案:

答案 0 :(得分:0)

The IDE does not maintain the symbols from user written js files by default. You need to add them explicitly to a project for them to be available in the code completion.

You can add a file or a library by going to Settings -> Language & Frameworks -> Javascript -> Libraries.

Then click on Add and add your file using the + button. It gives you an options to even add an entire directory.

答案 1 :(得分:0)

这是一个已知问题,请关注WEB-17099了解更新