prettier-plugin-sort-imports icon indicating copy to clipboard operation
prettier-plugin-sort-imports copied to clipboard

Error with files that have import { type Something}

Open Arilas opened this issue 3 years ago • 3 comments

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
}

Arilas avatar May 19 '22 21:05 Arilas

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.

IanVS avatar May 29 '22 04:05 IanVS

running into the same issue

avarun42 avatar Jun 03 '22 20:06 avarun42

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"
  },

yamazaki-sensei avatar Jun 06 '22 01:06 yamazaki-sensei