amatiasq / vsc-sort-imports

Sort ES6 imports automatically.
ISC License
58 stars 24 forks source link

Error sorting imports: TypeError: style is not a function #22

Closed stormwarning closed 6 years ago

stormwarning commented 6 years ago

I get the above error when running Sort imports in VS Code.

I have the following in my package.json

  "importSort": {
    ".js": {
      "parser": "babylon",
      "style": "ember"
    }
  }

I have import-sort and the custom sort style installed globally, rather than in the project dependencies, however it works as expected when running the CLI version so it seems like it should work with the editor plugin too.

amatiasq commented 6 years ago

The custom style should be installed locally, the CLI version works because it's installed globally but the one used by the editor plugin is not.

I'd keep this issue open to improve the error message though.

stormwarning commented 6 years ago

Ah that makes sense. Is it possible to have the plugin check for a global install if it's not found locally, or would that be an "upstream" issue? I had a look through the code but I couldn't quite suss out where I'd make that change if I was going to submit a PR.

amatiasq commented 6 years ago

The parser and the style are provided here by the import-sort-config library. So I think you can open a PR to it in that case.

Thanks in any case for the report, sorry for the late response.

jgomesmv commented 5 years ago

I'm also facing this issue when saving files. Is this error provoked by a bad configuration or something else? I have just installed the extension on my vs code and set this configs on my package.json: "importSort": { ".js, .jsx, .es6, .es": { "parser": "babylon", "style": "eslint", "options": {} }, ".ts, .tsx": { "parser": "typescript", "style": "tslint", "options": {} } },

amatiasq commented 5 years ago

@jgomesmv Without a deeper look I think this is related to the new version of import-sort, I need to check that when I have time. Can you please create an issue for your problem in particular?

jgomesmv commented 5 years ago

After some digging we have fixed the problem. You need to change your import sort configuration on package.json file. The ts style must be changed from tslint to eslint. Just like: image

Is it possible to improve the error message?

amatiasq commented 5 years ago

Good catch, I didn't see that