trivago / prettier-plugin-sort-imports

A prettier plugin to sort imports in typescript and javascript files by the provided RegEx order.
Apache License 2.0
3.36k stars 132 forks source link

SyntaxError: Unexpected token. Nestjs + prettier-plugin-sort-imports #169

Open jasus opened 2 years ago

jasus commented 2 years ago

Your Environment

Describe the bug

First error

When I add this prettier-plugin-sort-import with no configuration I have an error like this:

SyntaxError: This experimental syntax requires enabling one of the following parser plugin(s): "decorators-legacy", "decorators"

Second error

When I add decorators configuration:

"importOrderParserPlugins": ["classProperties", "decorators-legacy"]

have this error on each ts file:

SyntaxError: Missing semicolon. SyntaxError: Unexpected reserved word 'private' SyntaxError: Unexpected token, expected "{"

To Reproduce

Running prettier command to fix issues:

prettier --write **/*.{ts,js,json,md,html}

Expected behavior

No Syntax error using prettier-plugin-sort-imports

Screenshots, code sample, etc

Configuration File (cat .prettierrc, prettier.config.js, .prettier.js)

First error

.prettierrc

{
  "semi": false,
  "trailingComma": "none",
  "tabWidth": 2,
  "arrowParens": "always",
  "printWidth": 100,
  "singleQuote": false,
  "bracketSpacing": true,
  "endOfLine": "auto",
  "importOrder": ["^@nestjs/(.*)$", "^[./]"],
  "importOrderSeparation": true,
  "importOrderSortSpecifiers": true
}

Second error:

.prettierrc

{
  "semi": false,
  "trailingComma": "none",
  "tabWidth": 2,
  "arrowParens": "always",
  "printWidth": 100,
  "singleQuote": false,
  "bracketSpacing": true,
  "endOfLine": "auto",
  "importOrder": ["^@nestjs/(.*)$", "^[./]"],
  "importOrderSeparation": true,
  "importOrderSortSpecifiers": true,
  "importOrderParserPlugins": ["classProperties", "decorators-legacy"]
}
samchon commented 2 years ago

I've solved this problem by adding a more value typescript on importOrderParserPlugins.

ducker-dev commented 2 years ago

@samchon And what exactly values did you add there that everything worked?

aJonghunPark commented 2 years ago

@ducker-dev "importOrderParserPlugins": ["typescript", "classProperties", "decorators-legacy"]

davidkhierl commented 1 year ago

I have this config

importOrderParserPlugins: [
    'typescript',
    'classProperties',
    "[\"decorators\", { \"decoratorsBeforeExport\": true }]"
  ],

but now I'm getting this SyntaxError: Decorators cannot be used to decorate parameters.

I'm using NestJS