prettier-plugin-sort-imports
prettier-plugin-sort-imports copied to clipboard
Error with files that have import { type Something}
Hey, this plugin doesn't work when types are imported inside {} of an import.
This is an example, and an error message.
✖ prettier --write:
[error] packages/[NDA]/index.tsx: SyntaxError: Unexpected token, expected "," (2:7)
[error] 1 | import {
[error] 2 | type ComponentProps,
[error] 3 | type ComponentType,
[error] 4 | memo,
[error] 5 | useCallback,
[error] 6 | useMemo,
[error] 7 | useRef,
[error] 8 | useState,
[error] 9 | } from 'react';
Your Environment
- Prettier version: 2.5.1
- node version v16.14.2:
- package manager: yarn@3
- IDE: VScode, CLI]
Configuration File (cat .prettierrc, prettier.config.js, .prettier.js)
{
"endOfLine": "lf",
"jsxSingleQuote": false,
"printWidth": 80,
"trailingComma": "all",
"singleQuote": true,
"importOrder": ["react(.*)$", "<THIRD_PARTY_MODULES>", "@NDA/(.*)$", "^[./]"],
"importOrderSeparation": true
}
This is caused by the project locking to an old babel version. It's fixed in IanVS/prettier-plugin-sort-imports if you'd like to give that a try.
running into the same issue
If yarn is used, this error could be solved by fixing babel packages to the newest versions like this:
"resolutions": {
"@babel/core": "^7.18.2",
"@babel/generator": "^7.18.2",
"@babel/parser": "^7.18.4",
"@babel/traverse": "^7.18.2",
"@babel/types": "^7.18.4"
},