You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After setting up a new SvelteKit project, adding the plugin (@ianvs/prettier-plugin-sort-imports), there's an error formatting some TS files:
[error] src/routes/sverdle/+page.server.ts: TypeError: Cannot read properties of undefined (reading 'push')
[error] at getSortedNodesByImportOrder (/Users/gyen/CODING/GitHub-Issue-Reproductions/import-sort-issue/node_modules/@ianvs/prettier-plugin-sort-imports/lib/src/utils/get-sorted-nodes-by-import-order.js:37:41)
[error] at getSortedNodes (/Users/gyen/CODING/GitHub-Issue-Reproductions/import-sort-issue/node_modules/@ianvs/prettier-plugin-sort-imports/lib/src/utils/get-sorted-nodes.js:66:95)
[error] at preprocessor (/Users/gyen/CODING/GitHub-Issue-Reproductions/import-sort-issue/node_modules/@ianvs/prettier-plugin-sort-imports/lib/src/preprocessors/preprocessor.js:44:65)
[error] at Object.defaultPreprocessor [as preprocess] (/Users/gyen/CODING/GitHub-Issue-Reproductions/import-sort-issue/node_modules/@ianvs/prettier-plugin-sort-imports/lib/src/preprocessors/default.js:8:44)
[error] at parse4 (file:///Users/gyen/CODING/GitHub-Issue-Reproductions/import-sort-issue/node_modules/prettier/index.mjs:20681:43)
[error] at async coreFormat (file:///Users/gyen/CODING/GitHub-Issue-Reproductions/import-sort-issue/node_modules/prettier/index.mjs:21146:7)
[error] at async formatWithCursor (file:///Users/gyen/CODING/GitHub-Issue-Reproductions/import-sort-issue/node_modules/prettier/index.mjs:21348:14)
[error] at async formatFiles (file:///Users/gyen/CODING/GitHub-Issue-Reproductions/import-sort-issue/node_modules/prettier/internal/cli.mjs:3468:18)
[error] at async main (file:///Users/gyen/CODING/GitHub-Issue-Reproductions/import-sort-issue/node_modules/prettier/internal/cli.mjs:3876:5)
[error] at async Module.run (file:///Users/gyen/CODING/GitHub-Issue-Reproductions/import-sort-issue/node_modules/prettier/internal/cli.mjs:3822:5)
src/routes/sverdle/+page.svelteTypeError: Cannot read properties of undefined (reading 'push')
at getSortedNodesByImportOrder (/Users/gyen/CODING/GitHub-Issue-Reproductions/import-sort-issue/node_modules/@ianvs/prettier-plugin-sort-imports/lib/src/utils/get-sorted-nodes-by-import-order.js:37:41)
at getSortedNodes (/Users/gyen/CODING/GitHub-Issue-Reproductions/import-sort-issue/node_modules/@ianvs/prettier-plugin-sort-imports/lib/src/utils/get-sorted-nodes.js:66:95)
at preprocessor (/Users/gyen/CODING/GitHub-Issue-Reproductions/import-sort-issue/node_modules/@ianvs/prettier-plugin-sort-imports/lib/src/preprocessors/preprocessor.js:44:65)
at Object.defaultPreprocessor [as preprocess] (/Users/gyen/CODING/GitHub-Issue-Reproductions/import-sort-issue/node_modules/@ianvs/prettier-plugin-sort-imports/lib/src/preprocessors/default.js:8:44)
at parse4 (file:///Users/gyen/CODING/GitHub-Issue-Reproductions/import-sort-issue/node_modules/prettier/index.mjs:20681:43)
at async textToDoc (file:///Users/gyen/CODING/GitHub-Issue-Reproductions/import-sort-issue/node_modules/prettier/index.mjs:20792:19)
Thanks for the reproduction, that was very helpful. The problem here is that you did not define a sort order for a plain old <TYPES>, and the file causing issues as a type import from './$types' which doesn't match any of your other type import order regexes. Adding "<TYPES>" somewhere in your importOrder will fix the issue.
That said, I'm going to keep this issue open because we should either do some default sorting in this case or (my preference) throw a better error message.
Let me know if you hit any other issues!
IanVS
changed the title
Error formatting a Svelte codebase
Confusing error thrown when no matching importOrder is found
Oct 31, 2024
Your Environment
Describe the bug
After setting up a new SvelteKit project, adding the plugin (
@ianvs/prettier-plugin-sort-imports
), there's an error formatting some TS files:To Reproduce
npm install
.npm run format
Expected behavior
Should format the non-ignored files in the codebase without errors.
Configuration File (cat .prettierrc, prettier.config.js, .prettier.js)
Contribute to @ianvs/prettier-plugin-sort-imports
The text was updated successfully, but these errors were encountered: