Closed thisissami closed 3 years ago
My guess is it has to do with this file here: https://github.com/amatiasq/vsc-sort-imports/blob/master/src/config-cache.ts - At a cursory glance, it doesn't look like it handles anything other than the default-sort-style
.
const config = clone(DEFAULT_CONFIGS);
const defaultSortStyle = getConfiguration<string>('default-sort-style');
Object.keys(config).forEach(key => {
config[key].style = require.resolve(
`import-sort-style-${defaultSortStyle}`
);
});
@jquense tagging you, as you contributed that file to the source code and can speak better to this.
The logic hasn't changed from v6 to v6.1.0 around how configs are resolved, only how often configs are watched for changes. The code above doesn't handle resolving anything but the defaults, because sort
itself will do that. @thisissami how are you configuring the style? Unsure why it'd stop working across a version here since the extension doesn't handle config loading logic (defers to import-sort for that)
I'm using vscode
's UI for extension settings. In there, I've typed in module-alias
. I then have of course import-sort-style-module-alias
added to my node_modules
, and the appropriate settings for said plugin in my package.json
. This has not been an issue for me until this release (though the v6.02
release had a different set of issues that rendered it impossible to use this extension on Ubuntu 18.04).
Any updates? Would love to use https://www.npmjs.com/package/import-sort-style-module-alias as my style of choice...
I had a similar issue and after a long time I figured out that neither the project's local node_modules folder nor the global node_module folder were on the search path for require.resolve()
inside the extension.
My solution was to add the global node_modules folders to .bashrc
via:
export NODE_PATH=/usr/lib/node_modules
then npm i -g import-sort-style-xyz
, then restart vscode and it should work.
I'm not an extensions developer, but I'm wondering whether it should be possible to have extensions access the current project's/workspace's node_modules folder.
@andrefox333, @thisissami, did you fix it?
I have about 30 repositories with this set and never had problems.
@fsmaia i just reverted to an earlier version and have been happy with that.
I can confirm that I needed to revert two versions (to 6.0.1
) to make it work.
Version 6.1.0
throws error:
6/4/2020, 12:05:08 PM:
----------------------
Cannot find module 'import-sort-style-module-alias'
Require stack:
/Users/daniel/.vscode/extensions/amatiasq.sort-imports-6.1.0/out/src/config-cache.js
/Users/daniel/.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
Version 6.0.2
throws error:
Command 'Sort imports' resulted in an error (Running the contributed command: 'sort-imports.sort' failed.)
Specs: MacOS Version: 10.14.6 VSCode Version: 1.45.1
This is still happening in 6.2.2
Feels like this is the root of the issue: https://github.com/amatiasq/vsc-sort-imports/commit/5ff45e31885da8645064b9a534dad409d7c03b99#diff-943b8560c99a4d9dd2a7af3c4144d6d3afc983f82ea861eb4cba6c212a0d72d4L36-R38
6.1.0:
4/14/2021, 7:32:53 PM:
----------------------
Cannot find module 'import-sort-style-module-tsconfig'
Require stack:
- /Users/secondfry/.vscode/extensions/amatiasq.sort-imports-6.1.0/out/src/config-cache.js
- /Users/secondfry/.vscode/extensions/amatiasq.sort-imports-6.1.0/out/src/extension.js
- /Users/secondfry/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/loader.js
- /Users/secondfry/Applications/Visual Studio Code.app/Contents/Resources/app/out/bootstrap-amd.js
- /Users/secondfry/Applications/Visual Studio Code.app/Contents/Resources/app/out/bootstrap-fork.js
6.0.2:
[2021-04-14 19:27:31.185] [exthost] [error] onWillSaveTextDocument-listener from extension 'amatiasq.sort-imports' threw ERROR
[2021-04-14 19:27:31.185] [exthost] [error] Error: Cannot find module 'import-sort-style-module-tsconfig'
Require stack:
- /Users/secondfry/.vscode/extensions/amatiasq.sort-imports-6.0.2/out/src/sort.js
- /Users/secondfry/.vscode/extensions/amatiasq.sort-imports-6.0.2/out/src/on-save.js
- /Users/secondfry/.vscode/extensions/amatiasq.sort-imports-6.0.2/out/src/extension.js
- /Users/secondfry/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/loader.js
- /Users/secondfry/Applications/Visual Studio Code.app/Contents/Resources/app/out/bootstrap-amd.js
- /Users/secondfry/Applications/Visual Studio Code.app/Contents/Resources/app/out/bootstrap-fork.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1019:15)
at Function.v.resolve (/Users/secondfry/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/loader.js:4:756)
at /Users/secondfry/.vscode/extensions/amatiasq.sort-imports-6.0.2/out/src/sort.js:35:37
at Array.forEach (<anonymous>)
at Object.sort (/Users/secondfry/.vscode/extensions/amatiasq.sort-imports-6.0.2/out/src/sort.js:34:25)
at listener (/Users/secondfry/.vscode/extensions/amatiasq.sort-imports-6.0.2/out/src/on-save.js:42:31)
at P._deliverEventAsync (/Users/secondfry/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:86:30117)
at P._deliverEventAsyncAndBlameBadListeners (/Users/secondfry/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:86:29345)
at P.$participateInSave (/Users/secondfry/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:86:29046)
6.0.1 uses "import-sort": "^5.0.0",
which seems to ignore default-sort-style completely.
That issue is not reproducible anymore with various local test setups since https://github.com/amatiasq/vsc-sort-imports/pull/83 merge.
You have to give us a repository where you have the issue 100% of the time to allow more investigation.
Thanks.
Fixed in 6.2.6 version.
I use https://www.npmjs.com/package/import-sort-style-module-alias to handle my aliases within my project in a specific manner. When I updated to
v6.1.0
,sort-imports
no longer seems to be able to loadimport-sort-style-module-alias
. Whenever I try to run theSort imports
command, theOUTPUT
tab (same area asTERMINAL
) reads something like:This was never an issue previously, and I have re-installed
import-sort-style-module-alias
to make sure that i didn't accidentally remove it. I think a little bug has been introduced when generating the path-name to find custom sort-style plugins. probably a typo somewhere?