emmetio / sublime-tern

TernJS plugin for Sublime Text
222 stars 13 forks source link

Node require files #35

Open hoagy-davis-digges opened 10 years ago

hoagy-davis-digges commented 10 years ago

I can't seem to get sublime-tern to recognise modules imported through node's require function, aside from the core modules. It is currently spitting out this if I try to require() any non-core modules:

https://gist.github.com/hoagy-davis-digges/7379824

Update: I can get the autocompletion working by putting in the file paths:

express = require('node_modules/express/index'); nodeio = require('node_modules/node.io/index')

this gets rid of the first two errors, but the rest still slow down the system. It looks like tern is looking for all the files which are being required in the root project directory, instead of in the correct node_modules folder, any ideas on why it might be doing that?

Thanks

sergeche commented 10 years ago

Do you have most recent version of plugin? I’ve fixed similar issue recently: it tries to append .js extension for Node module names.

andersekdahl commented 10 years ago

@sergeche How did you fix that? I've just downloaded the plugin (via Package Control) and jump to definition only works if the required file name ends with ".js". So require("./utils"); doesn't work, but require("./utils.js"); does.

sergeche commented 10 years ago

If it can’t find ./utils file, it will try ./utils.js: https://github.com/emmetio/sublime-tern/blob/master/tern.py#L159 Make sure you’ve configured your project properly, as described in http://emmet.io/blog/sublime-tern/

andersekdahl commented 10 years ago

I have configured the project from that post, but I can't seem to get it to work.

My project files tern section looks like this:

    "ternjs": {
        "exclude": ["node_modules/**"],
        "include": ["src/**/*.js"],
        "libs": ["browser"],
        "plugins": {
            "node": {},
            "angular": {}
        }
    }

And the code I'm trying to use it with:

var model = require("../model");
var item = model.Item();

When I apply jump-to-definition on model.Item() it opens model.js only if I add ".js" in the require statement.