Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken Pipe #14

Closed
LeonardoGentile opened this issue Aug 30, 2016 · 33 comments
Closed

Broken Pipe #14

LeonardoGentile opened this issue Aug 30, 2016 · 33 comments

Comments

@LeonardoGentile
Copy link

Hi,
I'm on Mac Os, using node 6.3.1, Sublime Text 3114.

I've followed the installation instruction and already tried the suggested troubleshooting, but I had not luck. I've manually set the path to: "/Users/foo/.nvm/versions/node/v6.3.1/bin/node"

I've tested this on a jsx file, I place the cursor under an components that I need to import, then either by hitting a shortcut or using the command palette I launch "Import word under cursor" and I get this error message:

{'fileContent': 'import React from \'react\';\n\n\nimport Header from "./Header";\n\n\nexport default class Layout extends React.Component {\n  static propTypes = {\n    name: React.PropTypes.string,\n  };\n\n  constructor(props) {\n    super(props);\n  }\n\n  render() {\n    return (\n      <Header/>\n      <Footer />\n    );\n  }\n}\n', 'command': 'word', 'commandArg': 'Footer', 'pathToFile': '/Users/foo/Projects/react-adminlte-custom/src/components/Layout.jsx'}
Traceback (most recent call last):
  File "/Applications/Coding/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 568, in run_
    return self.run(edit, **args)
  File "import-js in /Users/foo/Library/Application Support/Sublime Text 3/Installed Packages/ImportJS.sublime-package", line 158, in run
BrokenPipeError: [Errno 32] Broken pipe
@lencioni
Copy link
Contributor

What version of import-js do you have installed? You can find this out by running importjs --version from the command line.

@LeonardoGentile
Copy link
Author

The version is 1.1.0

@trotzig
Copy link
Contributor

trotzig commented Aug 31, 2016

Could you run importjsd logpath, then open the file returned by that
command? There might ve something interesting in there.

On Wednesday, 31 August 2016, LeonardoGentile [email protected]
wrote:

The version is 1.1.0


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#14 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAjS5ewwyuDIMjJTyr352mYCQAn-amuLks5qlT2YgaJpZM4JwlPh
.

@bcaplan
Copy link

bcaplan commented Aug 31, 2016

I'm getting the exact same error. Using Sublime 3103 and import-js 1.1.0. The log file you mentioned checking (found at the path returned by importjsd logpath) is empty.

{'command': 'fix', 'fileContent': '', 'pathToFile': None}
Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 568, in run_
    return self.run(edit, **args)
  File "import-js in /Users/brandon/Library/Application Support/Sublime Text 3/Installed Packages/ImportJS.sublime-package", line 158, in run
BrokenPipeError: [Errno 32] Broken pipe

@trotzig
Copy link
Contributor

trotzig commented Aug 31, 2016

Cool, thanks for providing more context @bcaplan! Could you try running importjsd from the command-line? I have a feeling this will break somehow. The sublime plugin is using this command to start a background process which it will interact with.

@lencioni
Copy link
Contributor

What version of the sublime plugin are you using? (e.g. 1.0.0 or 1.0.1)

@bcaplan
Copy link

bcaplan commented Sep 1, 2016

@trotzig Happy to help!
Running importjsd from the command line:

$ importjsd
ImportJS (v1.1.0) DAEMON active. Logs will go to: /var/folders/f0/1p1s_ydn2ms7jgbr0s13lst40000gn/T/importjs.log

Then it seems to wait until I interrupt.

@lencioni I'm using version 1.0.1 of the Sublime plugin.

@trotzig
Copy link
Contributor

trotzig commented Sep 1, 2016

Then it seems to wait until I interrupt.

Yeah, that's expected behavior.

Could you post the output from the Sublime console where it says "ImportJS loaded with environment:"? I wonder if this is a PATH issue. You can obfuscate any paths or settings you don't want to share publicly. It's possible that the PATH doesn't contain the folder where importjsd is located.

@LeonardoGentile
Copy link
Author

LeonardoGentile commented Sep 1, 2016

As @bcaplan sais also my log file is empty.
My version of the plugin is 1.0.1 and importjs from npm is 1.1.0

I have another clue: the plugin sometimes works. Meaning that from time to time it works on some jsx file, then even in the same file it starts not to work logging the error described in the first post and then after that it won't work anymore for any file.
In any case it shouldn't be a path problem because sometimes it executes, it seems more a problem related to the file parsing, maybe some char in the file conflicts somehow with the plugin.

How sometimes it works/doesn't work seems not to be predictable, let me know if I can I do something more to track down this problem.

@bcaplan
Copy link

bcaplan commented Sep 1, 2016

@trotzig It doesn't appear to be a PATH issue since I am able to resolve it in the Sublime console:

>>> print(os.popen("which importjsd").read())
/usr/local/bin/importjsd

I have a bit more info I discovered on the behavior. This might be what @LeonardoGentile was seeing as well with his intermittent success.

If I relaunch Sublime, I am able to get it to work with the word command. And that command will continue to work after the first time. If at any point I try to use the fix command, it will throw the following error the first time, then the broken pipe error reported above every time after that. Once this error has happened, the word command ceases to work again until relaunching Sublime.

{'command': 'fix', 'pathToFile': '/Users/brandon/test/components/Test.jsx', 'fileContent': '\nReact.PropTypes.bool.isRequired'}

Traceback (most recent call last):
  File "./json/scanner.py", line 30, in _scan_once
IndexError: string index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./json/decoder.py", line 368, in raw_decode
  File "./json/scanner.py", line 32, in _scan_once
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 568, in run_
    return self.run(edit, **args)
  File "/Users/brandon/Library/Application Support/Sublime Text 3/Packages/ImportJS/import-js.py", line 162, in run
    result = json.loads(resultJson)
  File "./json/__init__.py", line 319, in loads
  File "./json/decoder.py", line 352, in decode
  File "./json/decoder.py", line 370, in raw_decode
ValueError: No JSON object could be decoded

@trotzig
Copy link
Contributor

trotzig commented Sep 1, 2016

Everyone, thanks for helping out. I managed to reproduce the issue locally by trying to import inside an anonymous file (one that hasn't yet got a filename). I just submitted version 1.1.1 of the npm module, so all you need to do to is

npm install -g import-js

We should have caught this earlier. But neither me, @lencioni, or any other of the core members of import-js use the Sublime plugin on a daily basis. Without you folks reporting stuff like this, it would have never been caught. Thanks for making import-js better! 😍

@trotzig
Copy link
Contributor

trotzig commented Sep 1, 2016

I'm going to close this with the assumption that 1.1.1 fixes the issue. If you still get the error, please reopen!

@trotzig trotzig closed this as completed Sep 1, 2016
@bcaplan
Copy link

bcaplan commented Sep 1, 2016

@trotzig I'm still seeing the issue running 1.1.1 😖 . The file I've been testing with is saved to disk.

@bcaplan
Copy link

bcaplan commented Sep 1, 2016

@trotzig Thanks for all your help on this, it's a really great utility!

I just noticed (and corrected) a typo above in which I stated I was getting an error with the import command. There is no such command, it was the fix command I was having an issue with.

@trotzig
Copy link
Contributor

trotzig commented Sep 1, 2016

That's too bad... 😢

Did you restart Sublime after upgrading?

@trotzig trotzig reopened this Sep 1, 2016
@trotzig
Copy link
Contributor

trotzig commented Sep 1, 2016

(not that I really think that's going to help)

@bcaplan
Copy link

bcaplan commented Sep 1, 2016

@trotzig This might actually be caused by an odd conflict with ESLint. I tried running the fix command from importjs on the command line and it threw an error in there complaining about my .eslintrc. I'm not sure why it was executing ESLint or why I hadn't run into this error when actually linting 😛.

Commenting out the offending line in my .eslintrc fixed it!

For posterity, I had the eslint-config-airbnb-base module installed and the following in my .eslintrc:

{
  "extends": [
    "airbnb"
  ]
}

@trotzig
Copy link
Contributor

trotzig commented Sep 1, 2016

That's interesting. It uses eslint under the hood to find all undefined variables (and unused imports too). We should handle this better though, so I filed an issue over at the main project to track: Galooshi/import-js#348

@bcaplan
Copy link

bcaplan commented Sep 1, 2016

Ah, that makes sense. Thanks again for the help!

@trotzig
Copy link
Contributor

trotzig commented Sep 1, 2016

When you eslint your project, do you rely on a globally installed eslint + plugins or do you use local ones in the node_modules folder? Import-js uses the latter.

@trotzig
Copy link
Contributor

trotzig commented Sep 1, 2016

I'm closing this once more. Thanks for your patience.

@bcaplan
Copy link

bcaplan commented Sep 1, 2016

We have it installed locally with that plugin in node_modules.

@lencioni
Copy link
Contributor

lencioni commented Sep 1, 2016

@bcaplan if you have eslint-config-airbnb-base installed, I believe you need to extend airbnb-base, not airbnb.

{
  "extends": [
    "airbnb-base"
  ]
}

@bcaplan
Copy link

bcaplan commented Sep 1, 2016

@lencioni It seems to work either way. Here's the error it has in case anyone is curious:

Error: /Users/brandon/test/node_modules/eslint-config-airbnb-base/rules/style.js:
    Configuration for rule "indent" is invalid:
    Value "data["1"].outerIIFEBody" has additional properties.

@bcaplan
Copy link

bcaplan commented Sep 1, 2016

According to eslint/eslint#6655 this can happen if running something that uses ESLint 2.x (which is the version bundled with import-js). I hopped into my local import-js module folder and upgraded ESLint to 3.x. It fixed the issue with the airbnb plugin.

I guess the problem is that it's able to us an .eslintrc outside the scope of its own module which opens it up to conflicts like this, especially if there's a version disparity.

@LeonardoGentile
Copy link
Author

Unlike @bcaplan I don't have a locally installed eslint, mine is global and its version is v3.1.1
I've cd into the gloabal installation of importjs and I've also noticed that it's using eslint [email protected].

So maybe this version mismatch could be the cause

@trotzig
Copy link
Contributor

trotzig commented Sep 2, 2016

This version mismatch is unfortunate, and the dependency between the locally installed eslint and the eslint used by import-js needs to be cut or improved in some way.

We use the local eslint configuration for two reasons:

  • to prevent trying to import global variables (e.g. jQuery, jasmine)
  • to support the specific javascript flavor that the local project uses (e.g. React)

We could introduce a globals configuration to import-js to avoid having to inherit from eslint config. And maybe we can try to cover as many flavors as possible for the internal eslinting done by import-js? If we add support for enough stuff, we wouldn't have to use local config.

Let's continue the discussion over at the main project since this isn't really sublime-specific: Galooshi/import-js#348

@lencioni
Copy link
Contributor

lencioni commented Sep 2, 2016

globals in import-js config isn't great, because they might be specific to any particular file (as defined by globals comments or .eslintrc files in sub-directories).

@pranjaltech
Copy link

pranjaltech commented Feb 14, 2018

I am facing the same error while using import-js, haven't been able to find a fix.

Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 812, in run_
    return self.run(edit, **args)
  File "import-js in /Users/pranjal/Library/Application Support/Sublime Text 3/Installed Packages/ImportJS.sublime-package", line 156, in run
BrokenPipeError: [Errno 32] Broken pipe

Version info is as follows:

npm @ 5.6.0
node @ 8.9.4
importjs @ 2.10.0
sublime-import-js @ 1.2.0

@trotzig @lencioni please help?

@trotzig
Copy link
Contributor

trotzig commented Feb 14, 2018

This issue was filed when we were still relying on eslint @pranjaltech. My guess would be that importjs isn't available on the PATH inside sublime. Can you run importjs in a terminal outside sublime?

@pranjaltech
Copy link

@trotzig Yep, I can run importjs outside sublime.

$ which importjs
/usr/local/bin/importjs

I noticed that running importjs is not giving any useful output. Eg. -

$ importjs fix ./source/components/Post.js

The output is:

{
  "fileContent": "// The actual contents of the file",
  "messages": [],
  "unresolvedImports": {}
}

@pranjaltech
Copy link

@trotzig It's working now! Thanks for pointing me in the right direction –

My guess would be that importjs isn't available on the PATH inside sublime.

I had recently downgraded from node@9 to node@8 via homebrew, but instead of unlinking the previously installed version, I'd just added the node@8 path to my ~/.zshrc. After reading your comment I realised that Sublime isn't reading from my ~/.zshrc file.

To fix the issue, I just ran:

brew unlink node
brew link node@8 --force
npm uninstall -g import-js
npm install -g import-js

and it works!

@trotzig
Copy link
Contributor

trotzig commented Feb 15, 2018

Awesome @pranjaltech, I'm glad you got it working!

@trotzig trotzig closed this as completed Feb 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants