Closed vincerubinetti closed 11 months ago
Hmm, it looks like it 's because of the lack of type
before the import { Table }
, interesting! It's probably getting confused since Table
already exists as a value (as opposed to a type) in the scope. Not sure this is a really a bug, it's definitely my mistake. But perhaps it'd be good to guard against this somehow?
i've been using it no problem for a week till today where i got the same error
["ERROR" - 5:55:13 PM] Cannot read properties of undefined (reading 'buildError') TypeError: Cannot read properties of undefined (reading 'buildError')
I also get the error with trivago's package. https://github.com/trivago/prettier-plugin-sort-imports/issues/228
@a-somani there is probably a syntax error in your file.
@vincerubinetti I'd be happy to review a PR if you'd like to try adding a nicer error message!
this is my .prettierrc.json
{
"plugins": ["@ianvs/prettier-plugin-sort-imports"],
"importOrder": [
"<BUILTIN_MODULES>",
"^react($|/)",
"^react-dom($|/)",
"^next($|/)",
"<THIRD_PARTY_MODULES>",
"",
"^@(styles|interfaces|services|components|lib|utils|artifacts|contracts|pages|hooks|layout|middleware|schemas|shared|contexts)($|/).*",
"^[./]"
],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true
}
i have not changed it since i used it last week when it was working. perhaps there was a vscode update or just the prettier vscode extension?
This is not a problem in the plugin or prettier, it's a problem somewhere in the file that you are trying to format.
do you know if theres an easier way to debug prettier in my file? im not sure whats causing Cannot read properties of undefined (reading 'buildError')
Is it a TypeScript file? If so, you can try compiling it with tsc
and see if it gives you an error. Or, try deleting one import at a time until the error goes away, and then you'll know which one it was.
I fixed it! I had named my react component the same as one of my imports. i resolved it by commenting out 1 line at a time till my prettier vscode plugin was no longer red. also found help with using yarn prettier */.tsx --check
Closing because it's unfortunately unlikely i'll have the time to be able to dive in and figure out what to change and how.
Your Environment
Describe the bug
See error log below.
To Reproduce
This is the file I'm trying to format. Still trying to narrow down what is tripping up the plugin.
Configuration File (cat .prettierrc, prettier.config.js, .prettier.js)
I have tried removing the other plugins, and there is no effect. If I remove just this plugin, prettier is able to format the document.
Error log
Contribute to @ianvs/prettier-plugin-sort-imports