amatiasq / vsc-sort-imports

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

Cannot find module 'import-sort-style-module-alias-x' #82

Closed dkoprowski closed 3 years ago

dkoprowski commented 3 years ago

Hi, I have a fresh install of my project on a new machine and suddenly import-sort stopped working. In the output log I see this:

4/13/2021, 3:45:10 PM:
----------------------
Cannot find module 'import-sort-style-module-alias-x'
Require stack:
- /Users/danielkoprowski/.vscode/extensions/amatiasq.sort-imports-6.2.4/out/config-cache.js
- /Users/danielkoprowski/.vscode/extensions/amatiasq.sort-imports-6.2.4/out/sort.js
- /Users/danielkoprowski/.vscode/extensions/amatiasq.sort-imports-6.2.4/out/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

This is my importSort in package.json.

  "importSort": {
    ".js, .jsx, .es6, .es": {
      "parser": "babylon",
      "style": "module-alias",
      "options": {
        "alias": [
          "~~test",
          "~assets",
          "~components",
          "~config",
          "~consts",
          "~ducks",
          "~helpers",
          "~hooks",
          "~routes",
          "~scenes",
          "~services"
        ],
        "overrideBuiltinModules": true
      }
    },
    ".ts, .tsx": {
      "parser": "typescript",
      "style": "module-alias",
      "options": {
        "alias": [
          "~~test",
          "~assets",
          "~components",
          "~config",
          "~consts",
          "~ducks",
          "~helpers",
          "~hooks",
          "~routes",
          "~scenes",
          "~services"
        ]
      }
    }
  }

Everything is freshly installed. Strange that it doesn't work out-of-the-box. Do you have any ideas?


VS Code extension

sort-imports amatiasq.sort-imports VSC Sort Import
v6.2.4

And packages:

    "import-sort-parser-typescript": "^6.0.0",
    "import-sort-style": "^6.0.0",
    "import-sort-style-module-alias": "^1.1.0",

CLI

It works well from CLI:

npx import-sort-cli [FILE]

It worked well so it seems like a bug in the extension.


Previously I've created an issue in "import-sort-style-module-alias" repo.

https://github.com/fsmaia/import-sort-style-module-alias/issues/9#

dkoprowski commented 3 years ago

@secondfry @amatiasq Hi, I downloaded the newest extension version but the issue is still here.

Maybe my config is wrong somehow?

How can I help you track this down?

4/15/2021, 3:03:42 PM:
----------------------
Cannot find module 'import-sort-style-module-alias-x'
Require stack:
- /Users/danielkoprowski/.vscode/extensions/amatiasq.sort-imports-6.2.5/out/config-cache.js
- /Users/danielkoprowski/.vscode/extensions/amatiasq.sort-imports-6.2.5/out/sort.js
- /Users/danielkoprowski/.vscode/extensions/amatiasq.sort-imports-6.2.5/out/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
secondfry commented 3 years ago

@dkoprowski I've had issues with caching, try closing all VScode instances and reopen them.

dkoprowski commented 3 years ago

@secondfry I tried to restart VSCode, restart Mac, uninstall extension & install again. No success :(

It's strange that it says Cannot find module 'import-sort-style-module-alias-x' while I have "style": "module-alias", setting. (Notice -x postfix).

I also have in my packages json those dependencies:

    "import-sort-parser-typescript": "^6.0.0",
    "import-sort-style": "^6.0.0",
    "import-sort-style-module-alias": "^1.1.0",

Maybe there is some collision?

secondfry commented 3 years ago

@dkoprowski AFAIK extension ignores your package.json setting (may be wrong here, not a maintainer). Check your settings in VScode, feels like you have style with -x there.

dkoprowski commented 3 years ago

Ok, I managed to solve it. For some reason, I had module-alias-x in extension settings. Maybe it's from my settings sync extension.

image

Looks like package.json isn't ignored. In the docs they say:

sort-imports.default-sort-style: sorting style if package.json doesn't have import-sort key (default: eslint).

I tested it and when changing style to eslint sorting changes.

So it takes settings from package.json but if something is wrong in extension settings it doesn't work.

The ticket is solved, thanks for the help!