sublime-tern icon indicating copy to clipboard operation
sublime-tern copied to clipboard

Node require files

Open hoagy-davis-digges opened this issue 12 years ago • 4 comments

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

hoagy-davis-digges avatar Nov 08 '13 21:11 hoagy-davis-digges

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

sergeche avatar Nov 10 '13 14:11 sergeche

@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.

andersekdahl avatar Nov 26 '13 07:11 andersekdahl

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/

sergeche avatar Nov 26 '13 07:11 sergeche

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.

andersekdahl avatar Nov 26 '13 08:11 andersekdahl