Closed vinpac closed 8 years ago
gem install import_js
is the one you want, not gem install import-js
(as mentioned in the message when installing the package). However, it looks like you are using an older version of Ruby. Support for Ruby 1.9.3 ended February 2015, so it is probably a good time to upgrade to Ruby 2.x (2.3.0 was recently released), which should resolve this issue for you. Upgrading Ruby depends on your system
Thanks, but now i`m getting other error
Error when executing import-js: /home/murdock/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- import_js (LoadError)
from /home/murdock/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/murdock/.rbenv/shims/import-js:3:in `<main>'
Before this, there was another error saying the import-js couldn't be found in ~/.rbenv/shims/import-js
. My import-js is istalled in ~/.rvm/gems/ruby-2.3.0/gems/import_js-0.2.0
, so just created a link to the executable.
I also put the sublime files that I found on this repository on the import-js`s folder then sublime text started recognizing it as a package.
Thanks for trying out import-js @vini175pa! I've made some changes in the 0.2.1 release that will hopefully resolve your issues:
import-js
not being found, try following these steps (from the release notes for 0.2.1): Breaking change: The default Sublime setting for
executable
has changed to justimport-js
, from previously being~/.rbenv/shims/import-js
. If you were relying on the rbenv path, you need to override theexecutable
setting with a full path to the import-js executable. Create or edit<path-to-sublime>/Packages/User/ImportJS.sublime-settings
with something that looks like this:{ "executable": "/Users/henrictrotzig/.rbenv/shims/import-js" }
Please note that you can't use
~
to refer to the home directory, you need to specify the full path.
You shouldn't have to copy any files (I've updated the docs so that they don't mention that anymore). So start by making sure you don't have any copied files. Then re-install ImportJS
from Package Control to get the latest version.
Reopening for a while so that this issue is more discoverable (I suspect others are running into the same issues).
Install the ImportJS plugin via Package Control
- How can I do this? I haven't found import-js on package control: install package
of sublime text
Edited
I renamed the executable
to the right path, but now i'm getting other error.
Error when executing import-js: /home/murdock/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/dependency.rb:319:in `to_specs': Could not find 'import_js' (>= 0.a) among 16 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/.gem/ruby/2.3.0:/home/murdock/.rvm/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0', execute `gem env` for more information
from /home/murdock/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/dependency.rb:328:in `to_spec'
from /home/murdock/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_gem.rb:65:in `gem'
from /home/murdock/.rvm/gems/ruby-2.3.0/bin/import-js:22:in `<main>'
from /usr/bin/ruby_executable_hooks:15:in `eval'
from /usr/bin/ruby_executable_hooks:15:in `<main>'
I wonder if this is because you installed the gem using sudo gem install
. I'm not actually sure, but can you run gem install import_js
(without sudo), then try again?
It's confusing that the plugin has different names in different places. The canonical name is "import-js", but gems are to be named with underscores instead of dashes, so that's why you install the import_js
gem. Then when it is installed, it exposes an import-js
executable (since having underscores in cli tools is uncommon). And to top that off, the Sublime plugin is to be named with CamelCase, so it's "ImportJS". Sorry about all the naming confusion.
Thanks, finally I solved it. I followed these instructions http://stackoverflow.com/questions/18541695/installed-ruby-using-apt-get-install-ruby-2-0-0-succeeded-but-not-using-correct.
The i changed ImportJs.sublime-settings to the right path.
{
"executable": "/usr/local/bin/import-js"
}
And it finally worked.. Kinda of..
EDITED
I'm getting some errors though.
Error when executing import-js: /usr/local/lib/ruby/gems/2.3.0/gems/import_js-0.2.1/lib/import_js/importer.rb:105:in `run_eslint_command': <text>:3:6: Parsing error: Unexpected reserved word [Error] (ImportJS::ParseError)
1 problem
from /usr/local/lib/ruby/gems/2.3.0/gems/import_js-0.2.1/lib/import_js/importer.rb:53:in `fix_imports'
from /usr/local/lib/ruby/gems/2.3.0/gems/import_js-0.2.1/bin/import-js:40:in `<top (required)>'
from /usr/local/bin/import-js:23:in `load'
from /usr/local/bin/import-js:23:in `<main>'
Edited
Its not importing at the end. Fix all imports is requiring the same package everytime and when i try to 'import word unde cursor' it doesn't import, only opens a dropdown showing paths. And when you select one, it does nothing.
Thanks for your help. This is a great package, i really want to use it. I will give look at the code as soon as I can. Are you already using it? If so, on which text editor?
Great, I'm glad you solved it. Thanks for your persistence. I hope you'll find the tool useful!
Gah, I replied before reading your edits... Do you think you can paste the contents of the js file you are using? And perhaps your .importjs.json config as well?
I use the vim plugin myself. But there are three people on my team using the Sublime plugin.
First file: test.js
describe('Array', function() {
describe('#indexOf()', function () {
it('should return -1 when the value is not present', function () {
assert.equal(-1, [1,2,3].indexOf(5));
});
});
});
After "import word under cursor" on assert
var assert =
require('node_modules/mongoose/node_modules/mquery/node_modules/bluebird/js/main/assert');
describe('Array', function() {
describe('#indexOf()', function () {
it('should return -1 when the value is not present', function () {
assert.equal(-1, [1,2,3].indexOf(5));
});
});
});
.importjson.json -- It should be .importjs.json
{
"lookup_paths": [
"lib",
"models"
]
}
EDITED
After renaming the .importjs.json solved the first problem.
Now we`re almost there. I did a test here. I tried importing an model, like User (named User.js of the folder models) in a parent Directory. So the test.js was in "/test.js" and the model was "/models/User.js" . I imported it with importJs but the require was like this
var User = require("User")
It should be require("models/User")
.
And it's not working with modules, only local files. When I try with express or http, it just nothing happens.
package.json dependencies
"dependencies": {
"body-parser": "~1.13.2",
"cookie-parser": "~1.3.5",
"debug": "~2.2.0",
"express": "~4.13.1",
"express-session": "*",
"jade": "~1.11.0",
"mocha": "^2.3.4",
"mongoose": "*",
"morgan": "~1.6.1",
"passport": "^0.3.2",
"serve-favicon": "~2.3.0",
"socket.io": "*"
}
I think you are getting require("User")
instead of require("models/User")
because you have "models"
in your "lookup_paths"
config which tells ImportJS that modules can be loaded from that path directly.
Oh, i see. Thanks for your help. It seems almost everything is working fine now. The only thing that is not. Is that when there are more than one option. Example User.js. It shows a dropdown to choose wich one I want (models/User or node_modules/.../.../user.js), but when I press enter on one of them, nothing happens.
This is a great plugin, it will help me a lot!
Are those the actual options you see in the dropdown? I'm confused by the node_modules/.../.../user.js
one. As far as I know, we don't traverse up the folder structure.
Can you look at the Sublime console log (View
> Show Console
) and paste what you see from import-js? I just tried out resolving a dropdown and it worked. This is what I see in the console log:
['/Users/henrictrotzig/.rbenv/shims/import-js', '--word', 'IntlStore', '--filename', '/Users/henrictrotzig/brigade/app/assets/components/AbbreviatedNumber/index.jsx']
['/Users/henrictrotzig/.rbenv/shims/import-js', '--word', 'IntlStore', '--selections', 'IntlStore:0', '--filename', '/Users/henrictrotzig/brigade/app/assets/components/AbbreviatedNumber/index.jsx']
after that, the file is changed with my selection added as an import.
Also @vini175pa what version of sublime are you using?
No no, Sorry. I should have put some like "node_modules/path/to/module". I put "..." just to give an example. That path was just an example. Trying it on "express" the options are.
node_modules/express (main: index.js)
node_modules/express/lib/express
This is what i see in the console log:
['/usr/local/bin/import-js', '--filename', '/home/murdock/production/ReactServer/test.js']
['/usr/local/bin/import-js', '--selections', 'express:1', '--filename', '/home/murdock/production/ReactServer/test.js']
Traceback (most recent call last):
File "/home/murdock/.config/sublime-text-3/Packages/import-js/import-js.py", line 107, in on_done
ask_recurse(next(selections_iter, None))
File "/home/murdock/.config/sublime-text-3/Packages/import-js/import-js.py", line 102, in ask_recurse
on_selections_done(selected)
File "/home/murdock/.config/sublime-text-3/Packages/import-js/import-js.py", line 76, in <lambda>
rerun = lambda selections: self.rerun(edit, args, selections)
File "/home/murdock/.config/sublime-text-3/Packages/import-js/import-js.py", line 89, in rerun
self.run(edit, **args)
File "/home/murdock/.config/sublime-text-3/Packages/import-js/import-js.py", line 85, in run
self.view.replace(edit, entire_file_region, stdout)
File "/opt/sublime_text/sublime.py", line 685, in replace
raise ValueError("Edit objects may not be used after the TextCommand's run method has returned")
ValueError: Edit objects may not be used after the TextCommand's run method has returned
I'm using Sublime Text 3 Build 3083
Interesting. I use the same Sublime version. This is actually something I thought was going to be a problem, and I was somewhat surprised that it worked. Even though view.show_popup_menu
looks async (it has an on_done
callback) it is actually run synchronously for me (execution halts until the callback is called).
It looks like we might be able to use view.run_command("insert", { characters: ... })
instead of view.replace(...)
to avoid that. At least if I read this SO thread correctly: http://stackoverflow.com/questions/23287029/st3-simple-dummy-plugin-that-takes-and-input-from-user-and-print-in-at-the-curs
If you feel up for hacking a bit @vini175pa , you could try to make that change and report back if it works. Otherwise I'll look into it tomorrow. Though even if it works for me, a change like that is only going to be a guess since I probably won't be able to reproduce the bug.
Ok, I'll try. Thanks for your help :) and for your plugin
Solved it, I will try to solve some other problems I found. If you press ESC when the dropdown is showing the options, it will import the last option (or the first, I don't remember) anyway. I know nothing about python or how to make Sublime Plugins, but well, what Google + Stackoverflow can't do? lol
EDITED
I made a pull request with the changes
I'm no Python expert either, but it's amazing how much knowledge is online these days. Thanks for all your help, I really appreciate it!
@vini175pa if you can see any good ways to improve the documentation that would have helped you get up and running more smoothly, please suggest them or submit a PR!
@lencioni Ok, i will do it! [OFF] @trotzig, @lencioni Could you give me a help in some React ''problems/questions" I am having? I would like just some tips to build a entire application rendering in React (server and client sides) and if it`s good to do this? Could you message me?
I don't think GitHub has a message feature, and I don't have much experience with server side React so I'm not sure how helpful I'll be. You'll probably have better luck on stack overflow or IRC. https://facebook.github.io/react/support.html
Yeah, no experience with server-side here either.
Closing this with the assumption that we've cleared out all the blockers.
When i try to install import-js by gem it shows an error.
sudo gem install import-js
So I tried
sudo gem install import_js
How can I solve this? I really want to use this :)