daidodo / format-imports-vscode

Format imports and exports for JavaScript and TypeScript in VS Code.
https://marketplace.visualstudio.com/items?itemName=dozerg.tsimportsorter
MIT License
62 stars 5 forks source link

Exception: Cannot read properties of undefined (reading 'version') #71

Closed geoidesic closed 2 years ago

geoidesic commented 2 years ago

Code snippet triggering the exception

I have no idea what's triggering it.

All Logs

(Please open the output channel for "JS/TS Import/Export Sorter" and copy/paste ALL logs here) er.. the what? What is an "output channel" and where would I find it?

daidodo commented 2 years ago

@geoidesic

Could you share the logs when the issue happened? Thanks! Debug Mode

gggdomi commented 2 years ago

Similar problem here : open any .ts file, save it "Something is wrong. Please open the logs and report an issue." pop-up appears. Running v7.4.17

The logs:

[2022-04-11T12:07:10.083] [INFO] default - os: {
  arch: 'arm64',
  platform: 'darwin',
  type: 'Darwin',
  release: '21.4.0',
  totalmem: 34359738368,
  freemem: 2880716800,
  EOL: '\n'
}
[2022-04-11T12:07:10.084] [INFO] default - vscode: { version: '1.66.1' }
[2022-04-11T12:07:15.745] [INFO] vscode.resolveConfig - Resolving config for fileName: /Users/gui/Dev/loco/monoloco/src/back/src/features/cs/CMD_csLogin/controller.ts languageId: typescript
[2022-04-11T12:07:15.919] [ERROR] vscode.formatDocument - Found exception: TypeError: Cannot read properties of undefined (reading 'version')
    at /Users/gui/.vscode/extensions/dozerg.tsimportsorter-7.4.17/out/extension.js:2:1036324
    at Generator.next (<anonymous>)
    at /Users/gui/.vscode/extensions/dozerg.tsimportsorter-7.4.17/out/extension.js:2:1035632
    at new Promise (<anonymous>)
    at n (/Users/gui/.vscode/extensions/dozerg.tsimportsorter-7.4.17/out/extension.js:2:1035377)
    at /Users/gui/.vscode/extensions/dozerg.tsimportsorter-7.4.17/out/extension.js:2:1036068
    at /Users/gui/.vscode/extensions/dozerg.tsimportsorter-7.4.17/out/extension.js:2:1036632
    at Generator.next (<anonymous>)
    at /Users/gui/.vscode/extensions/dozerg.tsimportsorter-7.4.17/out/extension.js:2:1035632
    at new Promise (<anonymous>)
    at n (/Users/gui/.vscode/extensions/dozerg.tsimportsorter-7.4.17/out/extension.js:2:1035377)
    at t.enhanceWithEslint (/Users/gui/.vscode/extensions/dozerg.tsimportsorter-7.4.17/out/extension.js:2:1035989)
    at /Users/gui/.vscode/extensions/dozerg.tsimportsorter-7.4.17/out/extension.js:2:1042332
    at Generator.next (<anonymous>)
    at /Users/gui/.vscode/extensions/dozerg.tsimportsorter-7.4.17/out/extension.js:2:1041936
    at new Promise (<anonymous>)
    at n (/Users/gui/.vscode/extensions/dozerg.tsimportsorter-7.4.17/out/extension.js:2:1041681)
    at s (/Users/gui/.vscode/extensions/dozerg.tsimportsorter-7.4.17/out/extension.js:2:1042084)
    at /Users/gui/.vscode/extensions/dozerg.tsimportsorter-7.4.17/out/extension.js:2:1050401
    at Generator.next (<anonymous>)
    at /Users/gui/.vscode/extensions/dozerg.tsimportsorter-7.4.17/out/extension.js:2:1049919
    at new Promise (<anonymous>)
    at n (/Users/gui/.vscode/extensions/dozerg.tsimportsorter-7.4.17/out/extension.js:2:1049664)
    at l (/Users/gui/.vscode/extensions/dozerg.tsimportsorter-7.4.17/out/extension.js:2:1050232)
    at t.formatDocument (/Users/gui/.vscode/extensions/dozerg.tsimportsorter-7.4.17/out/extension.js:2:1837426)
    at /Users/gui/.vscode/extensions/dozerg.tsimportsorter-7.4.17/out/extension.js:2:1832324
    at p (/Users/gui/.vscode/extensions/dozerg.tsimportsorter-7.4.17/out/extension.js:2:1832388)
    at k._deliverEventAsync (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:83:31709)
    at k._deliverEventAsyncAndBlameBadListeners (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:83:30937)
    at k.$participateInSave (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:83:30638)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Thank you for all your work.

daidodo commented 2 years ago

Please try v7.4.18.

I couldn't reproduce the issue but can guess what might be wrong. Hope it will fix the issue. Thanks!

Athelian commented 2 years ago

I am also getting the same issue since very recently. Using 7.4.18. Here is my output.

[2022-04-12T19:39:08.318] [INFO] vscode.resolveConfig - Resolving config for fileName: /home/ath/web-app/src/modules/relationMapV2/genericMapSlice.js languageId: javascript
[2022-04-12T19:39:08.327] [ERROR] vscode.formatDocument - Found exception: [TypeError: Cannot read properties of undefined (reading 'version')
    at /home/ath/.vscode-server/extensions/dozerg.tsimportsorter-7.4.18/out/extension.js:2:1036494
    at Generator.next (<anonymous>)
    at /home/ath/.vscode-server/extensions/dozerg.tsimportsorter-7.4.18/out/extension.js:2:1035795
    at new Promise (<anonymous>)
    at n (/home/ath/.vscode-server/extensions/dozerg.tsimportsorter-7.4.18/out/extension.js:2:1035540)
    at /home/ath/.vscode-server/extensions/dozerg.tsimportsorter-7.4.18/out/extension.js:2:1036244
    at /home/ath/.vscode-server/extensions/dozerg.tsimportsorter-7.4.18/out/extension.js:2:1036802
    at Generator.next (<anonymous>)
    at /home/ath/.vscode-server/extensions/dozerg.tsimportsorter-7.4.18/out/extension.js:2:1035795
    at new Promise (<anonymous>)
    at n (/home/ath/.vscode-server/extensions/dozerg.tsimportsorter-7.4.18/out/extension.js:2:1035540)
    at t.enhanceWithEslint (/home/ath/.vscode-server/extensions/dozerg.tsimportsorter-7.4.18/out/extension.js:2:1036165)
    at /home/ath/.vscode-server/extensions/dozerg.tsimportsorter-7.4.18/out/extension.js:2:1042502
    at Generator.next (<anonymous>)
    at /home/ath/.vscode-server/extensions/dozerg.tsimportsorter-7.4.18/out/extension.js:2:1042106
    at new Promise (<anonymous>)
    at n (/home/ath/.vscode-server/extensions/dozerg.tsimportsorter-7.4.18/out/extension.js:2:1041851)
    at s (/home/ath/.vscode-server/extensions/dozerg.tsimportsorter-7.4.18/out/extension.js:2:1042254)
    at /home/ath/.vscode-server/extensions/dozerg.tsimportsorter-7.4.18/out/extension.js:2:1050571
    at Generator.next (<anonymous>)
    at /home/ath/.vscode-server/extensions/dozerg.tsimportsorter-7.4.18/out/extension.js:2:1050089
    at new Promise (<anonymous>)
    at n (/home/ath/.vscode-server/extensions/dozerg.tsimportsorter-7.4.18/out/extension.js:2:1049834)
    at l (/home/ath/.vscode-server/extensions/dozerg.tsimportsorter-7.4.18/out/extension.js:2:1050402)
    at t.formatDocument (/home/ath/.vscode-server/extensions/dozerg.tsimportsorter-7.4.18/out/extension.js:2:1837387)
    at l (/home/ath/.vscode-server/extensions/dozerg.tsimportsorter-7.4.18/out/extension.js:2:1832370)
    at /home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:99:30804
    at Object.edit (/home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:83:50207)
    at /home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:99:30791
    at m._executeContributedCommand (/home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:85:30760)
    at m.$executeContributedCommand (/home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:85:31302)
    at i._doInvokeHandler (/home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:89:13826)
    at i._invokeHandler (/home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:89:13510)
    at i._receiveRequest (/home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:89:12171)
    at i._receiveOneMessage (/home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:89:10841)
    at /home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:89:8947
    at u.invoke (/home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:58:145)
    at v.fire (/home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:58:1856)
    at d.fire (/home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:66:19034)
    at /home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:104:34275
    at u.invoke (/home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:58:145)
    at v.fire (/home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:58:1856)
    at d.fire (/home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:66:19034)
    at o._receiveMessage (/home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:66:23615)
    at /home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:66:21149
    at u.invoke (/home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:58:145)
    at v.fire (/home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:58:1856)
    at v.acceptChunk (/home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:66:15865)
    at /home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:66:14995
    at u.invoke (/home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:58:145)
    at v.fire (/home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:58:1856)
    at l._processReadQueue (/home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:104:21305)
    at l.acceptFrame (/home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:104:20961)
    at E._acceptChunk (/home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:104:18925)
    at /home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:104:15914
    at Socket.T (/home/ath/.vscode-server/bin/8dfae7a5cd50421d10cd99cb873990460525a898/out/vs/workbench/api/node/extensionHostProcess.js:104:13797)
    at Socket.emit (node:events:390:28)
    at Socket.emit (node:domain:475:12)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:199:23)]

Also thanks for all your work on this extension.

daidodo commented 2 years ago

Emm, I've released v7.4.19. That's not a fix but will log what caused the issue, hopefully. Could you test it and share the logs in Debug Mode? Thanks!

Athelian commented 2 years ago

Can confirm that my issue is fixed with v7.4.19! Thanks so much.

Here is my output with a successful format:

[2022-04-13T09:47:25.054] [INFO] vscode.resolveConfig - Resolving config for fileName: /home/ath/web-app/src/components/Form/DocumentsUpload/components/DocumentNavbarSecondRowContent/index.js languageId: javascript
[2022-04-13T09:47:25.062] [WARN] format-imports.loadESLintConfig - Failed to load ESLint config for fileName: /home/ath/web-app/src/components/Form/DocumentsUpload/components/DocumentNavbarSecondRowContent/index.js with error: Cannot read properties of undefined (reading 'version')
[2022-04-13T09:47:25.062] [INFO] format-imports.formatSource - Formatting /home/ath/web-app/src/components/Form/DocumentsUpload/components/DocumentNavbarSecondRowContent/index.js with enhanced config: {
  configurationFileName: 'import-sorter.json',
  autoFormat: 'off',
  formatExports: true,
  exclude: [ 'node_modules' ],
  excludeGlob: [],
  sortImportsBy: 'paths',
  groupRules: [
    '^react(-dom)?$',
    '^@angular/',
    '^vue$',
    '^node:',
    {},
    '^[@]',
    '^[.]'
  ],
  sortRules: { paths: [ '_', 'aA' ], names: [ '_', 'aA' ] },
  keepUnused: [],
  emptyLinesBetweenGroups: 1,
  emptyLinesAfterAllImports: 1,
  removeLastSlashInPath: false,
  removeLastIndexInPath: false,
  wrappingStyle: {
    maxBindingNamesPerLine: 1,
    maxDefaultAndBindingNamesPerLine: 2,
    maxExportNamesPerLine: 0,
    maxNamesPerWrappedLine: 1,
    ignoreComments: false
  },
  development: { enableDebug: false },
  insertFinalNewline: true,
  eol: 'LF',
  force: true,
  maxLineLength: 100,
  tabType: 'space',
  tabSize: 2,
  hasSemicolon: true,
  quoteMark: 'single',
  trailingComma: 'multiLine',
  bracketSpacing: true
}
[2022-04-13T09:47:25.095] [INFO] vscode.formatDocument - Finished format with no-op
daidodo commented 2 years ago

@Athelian, thanks for the logs!

I'm glad it's working but the issue is still there:

format-imports.loadESLintConfig - Failed to load ESLint config for fileName: /home/ath/web-app/src/components/Form/DocumentsUpload/components/DocumentNavbarSecondRowContent/index.js with error: Cannot read properties of undefined (reading 'version')

Just to confirm you don't use ESLint in your project, right? It'd be good if there is a demo project to root cause the issue.

Athelian commented 2 years ago

@daidodo You're welcome.

Actually I am running ESLint in this project, is it okay? I don't know too much about ESLint things unfortunately... So sorry for that and, sorry also but I cannot share the project code with you. I would if I could.

I'd be happy to send you other config files like .eslintrc if that would still be useful to you.

daidodo commented 2 years ago

This plugin can read ESLint configs and adjust the formatting. With the issue your ESLint config will not be considered.

A demo project which can re-produce the issue is enough. Thanks!

gggdomi commented 2 years ago

@daidodo v7.4.19 works for me too :)

In addition it now loads my prettier config, which failed in older versions 🎉

If it helps :

Athelian commented 2 years ago

@gggdomi Ohh yes confirmed I am on eslint v6 actually

daidodo commented 2 years ago

Thanks for the callout! Is there anything else?