amatiasq / vsc-sort-imports

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

`sort-imports` v6.0.2 & v6.1.0 does not work, had to revert to v6.0.1 #58

Closed T41WO closed 4 years ago

T41WO commented 4 years ago

After the last couple of updates, sort imports has stopped working for my setup, React & TypeScript project.

What details would you need to investigate?

amatiasq commented 4 years ago

Hi @T41WO basic information would be your sort import configuration, OS, VS Code version and the output for Sort Imports if any (View => Output, then on the dropdown at the right select "Sort Imports").

Might be related to https://github.com/amatiasq/vsc-sort-imports/issues/56, do you use custom style?

T41WO commented 4 years ago

Hi @amatiasq,

Current version of VS Code is 1.38.1, and nothing in the output window

I beg your pardon, that is not true. stand by.

T41WO commented 4 years ago

Hi @amatiasq,

"Unexpected token, expected "}" (d:\development.......\FILENAME:LINE NUMBER:...)" is shown in the output window.

amatiasq commented 4 years ago

@T41WO Is FILENAME a file in your project or a file of the extension?

T41WO commented 4 years ago

A file in my project.. It is wrongly implying a syntax error in that currently open file (at a specific location), which I want it to sort the imports in.

amatiasq commented 4 years ago

@T41WO I need for some way to reproduce this error in order to debug it and understand what's going on. I've 6.1.0 running successfully and I'm aware other people does too.

If this is the error in optput please doble check the file and if the error persists can you provide a repo with the smallest code to reproduce this issue?

What I would do is start removing parts of the file until it's reduced to just one or two lines and check if the error dissapears, that way we can isolate what part of the file is causing this error.

@jquense as discussed on #51 if this error were in a toast it have been clear for @T41WO what can be the cause.

T41WO commented 4 years ago

Ok. Will look further into this and get back to you with updates.

tdd commented 4 years ago

Hey @amatiasq! First, thanks a ton for this ext, it's awesome.

I used to use the ext pre-6.1.0 with no trouble, using a custom sorting style. I now get the same behavior as this issue or #56. I put some effort in a custom sorter for our training sessions and this is really too bad!

Some info:

Output of the extension:

Cannot find module 'import-sort-style-delicious'
Require stack:
- /Users/tdd/.vscode/extensions/amatiasq.sort-imports-6.1.0/out/src/config-cache.js
- /Users/tdd/.vscode/extensions/amatiasq.sort-imports-6.1.0/out/src/extension.js
- /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/loader.js
- /Applications/Visual Studio Code.app/Contents/Resources/app/out/bootstrap-amd.js
- /Applications/Visual Studio Code.app/Contents/Resources/app/out/bootstrap-fork.js

Module is of course available:

npm ls import-sort-style-delicious
… import-sort-style-delicious@1.0.2

I would really love to see this fixed. As there is no way to control / constrain an extension version in VSC (that I know of anyway), we're sort of helpless, can't roll it back to earlier versions.

Best,

amatiasq commented 4 years ago

Hi @tdd I know there is an option in settings to change the style but for dependency reasons we can't access custom styles from there.

In the documentation you can see the proper way to import custom styles.

I don't know how can that be working before 6.0.2.

I've tested with this in my package.json and it works:

  "importSort": {
    ".ts, .tsx": {
      "style": "delicious"
    }
  },
tdd commented 4 years ago

Hey @amatiasq thanks for replying!

I do have that config in place, used to work in 6.0.1, seems to fail since 6.1.0. Or perhaps it's the ext itself that breaks, dunno.

If I do install import-sort locally in my node_modules, does the ext honor my local version? That would let me check whether it's a version thing.

amatiasq commented 4 years ago

It should, please remember to always do "Developer: Reload window" after you change any configuration or add new packages just in case.

tdd commented 4 years ago

Hey there!

So FWIW I figured it out. I feel this is a bug, really.

The trouble was, I had the ext-level VSCode setting specifying the default sort style on my custom sort style. Despite it being in the workspace settings, it sounds like the ext was looking for it in global modules or something, as it didn't find it (and it was in the local node_modules).

Also, it tried to honor that setting despite my importSort setting in the project's package.json, which should have held priority and make that ext-level setting ignored.

When I removed the ext-level setting, the package.json settings were honored and the ext worked again.

Weeeeeeird.

Best,

amatiasq commented 4 years ago

Yes, the getConfig method from import-sort is pretty confusing and there is no practical way to bypass it on this extension. I'm happy you can continue working :)